Miracle:
稍微改了一下ServiceClientWrapper<T>,还是用泛型满足需求,前面忘了考虑你要使用原始类型的需求了
[阅读: 507] 2008-05-22 13:33:57
/// <summary>
/// This wrapper class contains the common behaviors across different ServiceClient class
/// </summary>
/// <typeparam name="T">The ServiceClient class. You need to make sure they all support State, Abort and ClientCredentials properly</typeparam>
public class ServiceClientWrapper<T>
{
T _instance;
Type type = null;
public T ServiceClient
{
get
{
return this._instance;
}
}
public ServiceClientWrapper()
{
type = typeof(T);
_instance = (T)System.Activator.CreateInstance(type);
}
#region Common behaviors across different ServiceClient classes
public CommunicationState State
{
get
{
return (CommunicationState)type.GetProperty("State").GetValue(_instance, null);
}
set
{
type.GetProperty("State").SetValue(_instance, value, null);
}
}
public void Abort()
{
type.InvokeMember("Abort", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance
| System.Reflection.BindingFlags.InvokeMethod, null, _instance, null);
}
public UserIdentity ClientCredentials
{
get
{
return (UserIdentity)type.GetProperty("ClientCredentials").GetValue(_instance, null);
}
set
{
type.GetProperty("ClientCredentials").SetValue(_instance, value, null);
}
}
#endregion
}
夫习拳艺者,对已者十之七八,对人者,仅十之二三耳。拳艺之道,深无止境。得其浅者,一人敌,得其深者,何尝不万人敌耶!
我的Google Picasa相册
我的新BLOG