Esempio n. 1
0
 /// <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);
             }
         }
     }
 }
Esempio n. 2
0
        /// <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);
                    }
                }
            }
        }
Esempio n. 3
0
 public ConstructorInfoEx(ConstructorInfo constructor)
 {
     if (constructor == null)
     {
         throw new ArgumentNullException("constructor");
     }
     _Constructor = constructor;
     _New         = Literacy.CreateNewObject(constructor);
 }
Esempio n. 4
0
 public MethodInfoEx(MethodInfo method)
 {
     if (method == null)
     {
         throw new ArgumentNullException("method");
     }
     _Method = method;
     _Caller = Literacy.Cache(method);
 }
Esempio n. 5
0
        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)));
        }
Esempio n. 6
0
        /// <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;
            }
        }
Esempio n. 7
0
        //======================以下是必须的============================================


        #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));
        }