Exemplo n.º 1
0
        /// <summary> 加载公开的静态的字段,参数hasNonPublic为true,则非公开的静态字段也一起加载
        /// </summary>
        /// <param name="hasNonPublic">是否一起加载非公开的静态字段</param>
        void ILoadMember.StaticField(bool hasNonPublic)
        {
            if (Loaded(hasNonPublic ? 3 : 4))
            {
                return;
            }
            if (Field == null)
            {
                Field = new ObjectPropertyCollection(Property.IgnoreCase);
            }
            var bf = BindingFlags.Public | BindingFlags.Static;

            if (hasNonPublic)
            {
                bf |= BindingFlags.NonPublic;
            }
            foreach (var f in Type.GetFields(bf))
            {
                if (Field.ContainsKey(f.Name) == false)
                {
                    Field.Add(ObjectProperty.Cache(f));
                }
            }
            Monitor.Exit(this);
        }
Exemplo n.º 2
0
        /// <summary> 加载非公开的实例字段
        /// </summary>
        void ILoadMember.NonPublicField()
        {
            if (Loaded(2))
            {
                return;
            }
            if (Field == null)
            {
                Field = new ObjectPropertyCollection(Property.IgnoreCase);
            }
            const BindingFlags bf = BindingFlags.NonPublic | BindingFlags.Instance;

            foreach (var f in Type.GetFields(bf))
            {
                Field.Add(ObjectProperty.Cache(f));
            }
            Monitor.Exit(this);
        }
Exemplo n.º 3
0
        /// <summary> 初始化对象属性,字段访问组件,ignoreCase参数指示是否需要区分大小写
        /// </summary>
        /// <param name="type">需快速访问的类型</param>
        /// <param name="ignoreCase">是否区分大小写(不区分大小写时应保证类中没有同名的(仅大小写不同的)属性或字段)</param>
        public Literacy(Type type, bool ignoreCase)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            Type           = type;
            _CallNewObject = PreNewObject;
            Property       = new ObjectPropertyCollection(ignoreCase);
            foreach (var p in Type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (p.GetIndexParameters().Length == 0) //排除索引器
                {
                    if (!Property.ContainsKey(p.Name))
                    {
                        var a = ObjectProperty.Cache(p);
                        Property.Add(a);
                    }
                }
            }
            ID  = Interlocked.Increment(ref Sequence);
            UID = Guid.NewGuid();
        }