Getter method's info.
Esempio n. 1
0
        /// <summary>
        /// Fast property access, using Reflection.Emit.
        /// </summary>
        public IList <GetterInfo> GetGetterDelegates(Type type)
        {
            List <GetterInfo> cachedGetters;

            if (_gettersCache.TryGetValue(type, out cachedGetters))
            {
                return(cachedGetters);
            }

            var gettersList = new List <GetterInfo>();
            var properties  = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in properties)
            {
                var getterDelegate = createGetterPropertyDelegate(type, property);
                if (getterDelegate == null)
                {
                    continue;
                }

                var info = new GetterInfo
                {
                    Name         = property.Name,
                    GetterFunc   = getterDelegate,
                    PropertyType = property.PropertyType,
                    MemberInfo   = property
                };
                gettersList.Add(info);
            }

            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

            foreach (var field in fields)
            {
                var getterDelegate = createGetterFieldDelegate(type, field);
                if (getterDelegate == null)
                {
                    continue;
                }

                var info = new GetterInfo
                {
                    Name         = field.Name,
                    GetterFunc   = getterDelegate,
                    PropertyType = field.FieldType,
                    MemberInfo   = field
                };
                gettersList.Add(info);
            }

            _gettersCache.Add(type, gettersList);
            return(gettersList);
        }
        /// <summary>
        /// Fast property access, using Reflection.Emit.
        /// </summary>
        public IList <GetterInfo> GetGetterDelegates(Type type)
        {
            var getterDelegates = _gettersCache.GetOrAdd(type, x => new Lazy <List <GetterInfo> >(
                                                             () =>
            {
                var gettersList = new List <GetterInfo>();
                var properties  = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                int index       = 0;
                foreach (var property in properties)
                {
                    var getterDelegate = createGetterPropertyDelegate(type, property, index);
                    index++;

                    if (getterDelegate == null)
                    {
                        continue;
                    }

                    var info = new GetterInfo
                    {
                        Name         = property.Name,
                        GetterFunc   = getterDelegate,
                        PropertyType = property.PropertyType,
                        MemberInfo   = property
                    };
                    gettersList.Add(info);
                }

                var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
                foreach (var field in fields)
                {
                    var getterDelegate = createGetterFieldDelegate(type, field);
                    if (getterDelegate == null)
                    {
                        continue;
                    }

                    var info = new GetterInfo
                    {
                        Name         = field.Name,
                        GetterFunc   = getterDelegate,
                        PropertyType = field.FieldType,
                        MemberInfo   = field
                    };
                    gettersList.Add(info);
                }

                return(gettersList);
            }));

            return(getterDelegates.Value);
        }
Esempio n. 3
0
        /// <summary>
        /// Fast property access, using Reflection.Emit.
        /// </summary>
        public IList<GetterInfo> GetGetterDelegates(Type type)
        {
            List<GetterInfo> cachedGetters;
            if (_gettersCache.TryGetValue(type, out cachedGetters))
                return cachedGetters;

            var gettersList = new List<GetterInfo>();
            var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (var property in properties)
            {
                var getterDelegate = createGetterPropertyDelegate(type, property);
                if (getterDelegate == null)
                    continue;

                var info = new GetterInfo
                {
                    Name = property.Name,
                    GetterFunc = getterDelegate,
                    PropertyType = property.PropertyType,
                    MemberInfo = property
                };
                gettersList.Add(info);
            }

            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (var field in fields)
            {
                var getterDelegate = createGetterFieldDelegate(type, field);
                if (getterDelegate == null)
                    continue;

                var info = new GetterInfo
                {
                    Name = field.Name,
                    GetterFunc = getterDelegate,
                    PropertyType = field.FieldType,
                    MemberInfo = field
                };
                gettersList.Add(info);
            }

            _gettersCache.Add(type, gettersList);
            return gettersList;
        }