public abstract class ClientBase<TChannel> : ICommunicationObject, IDisposable where TChannel : class
{
... public ClientCredentials ClientCredentials { get; }
...
}
这是wcf客户端代理的抽象泛型基类我现在有很多个派生出来的代理类,我能不能通过一个静态方法来访问这个ClientCredentials属性like:
static void foo(ClientBase<T> client)
{
client.ClientCredentials.OOXX;
}类似这个,这个方法应该怎么写?
{
... public ClientCredentials ClientCredentials { get; }
...
}
这是wcf客户端代理的抽象泛型基类我现在有很多个派生出来的代理类,我能不能通过一个静态方法来访问这个ClientCredentials属性like:
static void foo(ClientBase<T> client)
{
client.ClientCredentials.OOXX;
}类似这个,这个方法应该怎么写?
解决方案 »
- winform的datagridview的标题栏可不可以添加一个小按钮
- 用System.net.mail.MailMessage 向OUTLOOK发送会议邀请,循环会议的邀请和取消
- 求一个类似QQ的侧边选项卡控件
- c#显示swf文件的方法?
- 请问在Window Service程序中启用的线程中使用Mutex会生效吗?
- 初学Socket,有个问题实在想不明白,请高手帮帮忙阿!!!!谢谢
- 100分问个问题,不够可以再加..在.net下如何制作能够安静安装的安装包.
- C# Linq对DataTable分组求和
- ListView控件的Activation属性和FullRowSelect属性没有起到作用?
- 做完了怎么办?
- 如何通过代码设置横向或纵向打印,在线等
- 一个关于C#重命名文件的问题。。。
instance.ClientCredentials.UserName.Username="oo";
instance.clientCredentials.UserName.password="xx";
比较烦人不知大家可有好的解决方案,我就想写个静态方法,把每个代理类传进去,这个方法自动帮我设置好用户名和密码。
可是ClientCredentials不是某个接口的成员,也不某个公共基类的成员,所以在写这个静态方法的时候,我就没法进行多态了对泛型不了解,不知有没有相应的方法,请大家多多指教。
public interface IClientCredentialsAuth
{
ClientCredentials ClientCredentials { get; }
} public class ClientCredentials
{
public string Account { get; set; }
public string Password { get; set; }
} public abstract class ClientBase<T> : IDisposable, ICommunicationObject, IClientCredentialsAuth where T : class
{
public static void Auth(IClientCredentialsAuth auth, string acc, string pwd)
{
auth.ClientCredentials.Account = acc;
auth.ClientCredentials.Password = pwd;
} public ClientCredentials ClientCredentials
{
get { return new ClientCredentials() }
}
}
明白你的意思了,你直接没将清楚哦public static class AuthClass
{
public static void Foo<T>(ClientBase<T> client) where T : class
{
client.ClientCredentials.Account = "admin";
client.ClientCredentials.Password = "pwd";
}
}
{
public static void Foo<T>(this ClientBase<T> client) where T : class
{
client.ClientCredentials.Account = "admin";
client.ClientCredentials.Password = "pwd";
}
}加上this后就可以直接在服务代理类上调用了clientproxy.Foo<ClientProxyType>();