/// <summary>创建快速访问成员</summary> /// <param name="member"></param> /// <returns></returns> public static MemberInfoX Create(MemberInfo member) { if (member == null) { return(null); } switch (member.MemberType) { case MemberTypes.All: break; case MemberTypes.Constructor: return(ConstructorInfoX.Create(member as ConstructorInfo)); case MemberTypes.Custom: break; case MemberTypes.Event: return(EventInfoX.Create(member as EventInfo)); case MemberTypes.Field: return(FieldInfoX.Create(member as FieldInfo)); case MemberTypes.Method: return(MethodInfoX.Create(member as MethodInfo)); case MemberTypes.Property: return(PropertyInfoX.Create(member as PropertyInfo)); case MemberTypes.TypeInfo: case MemberTypes.NestedType: return(TypeX.Create(member as Type)); default: break; } return(null); }
/// <summary>静态快速赋值。若属性不存在,会抛出异常。不确定属性是否存在时,建议使用Create方法</summary> /// <param name="type"></param> /// <param name="target"></param> /// <param name="name"></param> /// <param name="value"></param> internal static void SetValue(Type type, Object target, String name, Object value) { if (type == null && target != null) { type = target.GetType(); } if (type == null) { throw new ArgumentNullException("type"); } if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } PropertyInfoX pix = Create(type, name); if (pix == null) { throw new Exception(string.Format("类{0}中无法找到{1}属性!", type.Name, name)); } pix.SetValue(target, value); }