/// <summary> 加载Setter /// </summary> public void LoadSetter() { if (Setter != PreSetter) { return; } lock (this) { if (Setter == PreSetter) //Setter未编译 { if (!CanWrite) //当前成员可写 { Setter = ErrorSetter; } else if (Field) { Setter = Literacy.CreateSetter((FieldInfo)MemberInfo); } else { Setter = Literacy.CreateSetter((PropertyInfo)MemberInfo); } } } }
/// <summary> 加载Getter /// </summary> public void LoadGetter() { if (Getter != PreGetter) { return; } lock (this) { if (Getter == PreGetter) //Getter未编译 { if (!CanRead) //当前对象不可读 { Getter = ErrorGetter; } else if (Field) { Getter = Literacy.CreateGetter((FieldInfo)MemberInfo); } else { Getter = Literacy.CreateGetter((PropertyInfo)MemberInfo); } } } }
public ConstructorInfoEx(ConstructorInfo constructor) { if (constructor == null) { throw new ArgumentNullException("constructor"); } _Constructor = constructor; _New = Literacy.CreateNewObject(constructor); }
public MethodInfoEx(MethodInfo method) { if (method == null) { throw new ArgumentNullException("method"); } _Method = method; _Caller = Literacy.Cache(method); }
public static Func <object, object[], object> CreateCaller(MethodInfo method) { if (method == null) { throw new ArgumentNullException(nameof(method)); } var caller = Literacy.CreateCaller(method); return(Convert <Func <object, object[], object> >((o, a) => caller(o, a))); }
/// <summary> 表示一个可以获取或者设置其内容的对象属性 /// </summary> /// <param name="property">属性信息</param> private ObjectProperty(PropertyInfo property) { Field = false; MemberInfo = property; //属性信息 OriginalType = property.PropertyType; var get = property.GetGetMethod(true); //获取属性get方法,不论是否公开 var set = property.GetSetMethod(true); //获取属性set方法,不论是否公开 if (set != null && //set方法不为空 property.GetIndexParameters().Length == 0) { CanWrite = true; //属性可写 Static = set.IsStatic; //属性是否为静态属性 IsPublic = set.IsPublic; } else if (property.DeclaringType.Name.StartsWith("<>f__AnonymousType")) //匿名类 { CanWrite = true; IsPublic = false; } if (get != null) //get方法不为空 { CanRead = true; //属性可读 Static = get.IsStatic; //get.set只要有一个静态就是静态 IsPublic = IsPublic || get.IsPublic; } ID = System.Threading.Interlocked.Increment(ref Literacy.Sequence); UID = Guid.NewGuid(); Init(); if (set == null && CanWrite) //匿名类的属性设置特殊处理 { Setter = (o, v) => { var field = ClassType.GetField("<" + Name + ">i__Field", (BindingFlags)(-1)); Setter = Literacy.CreateSetter(field, ClassType); Setter(o, v); }; } Attributes = new AttributeCollection(MemberInfo); var mapping = Attributes.First <IMemberMappingAttribute>(); if (mapping != null) { MappingName = mapping.Name; } }
//======================以下是必须的============================================ #region protected static TypeEx() { GetConstructorImplHandler = Literacy.CreateCaller(typeof(Type).GetMethod("GetConstructorImpl", BindingFlags.NonPublic | BindingFlags.Instance)); GetMethodImplHandler = Literacy.CreateCaller(typeof(Type).GetMethod("GetMethodImpl", BindingFlags.NonPublic | BindingFlags.Instance)); GetPropertyImplHandler = Literacy.CreateCaller(typeof(Type).GetMethod("GetPropertyImpl", BindingFlags.NonPublic | BindingFlags.Instance)); }