您的位置:首页 > 编程语言 > C#

C#反射读取和设置类的属性

2017-05-22 22:18 183 查看
/// <summary>
/// 获取web服务实例
/// </summary>
/// <typeparam name="T">服务代理类</typeparam>
/// <returns></returns>
public static T GetInsatnce<T>() where T : System.Web.Services.Protocols.SoapHttpClientProtocol
{
string fullWebUrlPath = string.Empty;
Type type = typeof(T);
object obj = Activator.CreateInstance(type);
T instance = obj as T;
System.Reflection.PropertyInfo propertyInfo = type.GetProperty("Url");
fullWebUrlPath = Prefix_WebServiceURL + string.Format("/{0}/{0}.asmx", type.Name);
propertyInfo.SetValue(obj, fullWebUrlPath, null);
return instance;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: