Beispiel #1
0
        private XTypeInfo(Type type, XBindingFlags flags)
        {
            this.type  = type;
            this.flags = flags;

            IEqualityComparer <string> rwKeyComparer;

            if ((flags & XBindingFlags.RWIgnoreCase) != 0)
            {
                rwKeyComparer = new IgnoreCaseEqualityComparer();
            }
            else
            {
                rwKeyComparer = EqualityComparer <string> .Default;
            }

            var fields     = new List <XFieldInfo>();
            var properties = new List <XPropertyInfo>();
            var indexers   = new List <XIndexerInfo>();
            var methods    = new List <XMethodInfo>();
            var rwFields   = new List <IXFieldRW>();

            GetItems(type, flags, fields, properties, indexers, methods);

            foreach (var item in fields)
            {
                var rwField = item as IXFieldRW;

                if (rwField == null)
                {
                    continue;
                }

                var attributes = item.FieldInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                if (attributes != null && attributes.Length != 0)
                {
                    foreach (RWFieldAttribute attribute in attributes)
                    {
                        var attributedFieldRW = new XAttributedFieldRW(rwField, attribute);

                        if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                        {
                            rwFields.Add(attributedFieldRW);
                        }
                    }
                }
                else
                {
                    rwFields.Add(rwField);
                }
            }

            foreach (var item in properties)
            {
                var rwField = item as IXFieldRW;

                if (rwField == null)
                {
                    continue;
                }

                var attributes = item.PropertyInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                if (attributes != null && attributes.Length != 0)
                {
                    foreach (RWFieldAttribute attribute in attributes)
                    {
                        var attributedFieldRW = new XAttributedFieldRW(rwField, attribute);

                        if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                        {
                            rwFields.Add(attributedFieldRW);
                        }
                    }
                }
                else
                {
                    rwFields.Add(rwField);
                }
            }

            rwFields.Sort((x, y) => x.Order.CompareTo(y.Order));

            this.fields     = fields.ToArray();
            this.properties = properties.ToArray();
            this.indexers   = indexers.ToArray();
            this.methods    = methods.ToArray();
            this.rwFields   = rwFields.ToArray();

            fieldsCache     = new NameCache <XFieldInfo>();
            propertiesCache = new NameCache <XPropertyInfo>();
            indexersCache   = new HashCache <RuntimeParamsSign, XIndexerInfo>();
            methodsCache    = new HashCache <RuntimeMethodSign, XMethodInfo>();
            rwFieldsCache   = new NameCache <IXFieldRW>();

            foreach (var item in fields)
            {
                fieldsCache[item.name] = item;
            }
            foreach (var item in properties)
            {
                propertiesCache[item.name] = item;
            }
            foreach (var item in indexers)
            {
                indexersCache[new RuntimeParamsSign(ParametersToTypes(item.PropertyInfo.GetIndexParameters()))] = item;
            }
            foreach (var item in methods)
            {
                methodsCache[new RuntimeMethodSign(item.MethodInfo.Name, ParametersToTypes(item.MethodInfo.GetParameters()))] = item;
            }
            foreach (var item in rwFields)
            {
                rwFieldsCache[item.Name] = item;
            }
        }
Beispiel #2
0
        private XTypeInfo(Type type, XBindingFlags flags)
        {
            Type  = type;
            Flags = flags;

            IEqualityComparer <string> rwKeyComparer;

            if ((flags & XBindingFlags.RWIgnoreCase) != 0)
            {
                rwKeyComparer = new IgnoreCaseEqualityComparer();
            }
            else
            {
                rwKeyComparer = EqualityComparer <string> .Default;
            }

            fields     = new XDictionary <string, XFieldInfo>(XDictionaryOption.AllowRepeat);
            properties = new XDictionary <string, XPropertyInfo>(XDictionaryOption.AllowRepeat);
            indexers   = new XDictionary <RuntimeParamsSign, XIndexerInfo>(XDictionaryOption.AllowRepeat);
            methods    = new XDictionary <RuntimeMethodSign, XMethodInfo>(XDictionaryOption.AllowRepeat);
            rwFields   = new Dictionary <string, IXFieldRW>(rwKeyComparer);

            GetItems(type, flags);

            var rwFieldList = new List <IXFieldRW>();

            foreach (var item in fields)
            {
                var rwField = item.Value as IXFieldRW;

                if (rwField == null)
                {
                    continue;
                }

                var attributes = item.Value.FieldInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                if (attributes != null && attributes.Length != 0)
                {
                    foreach (RWFieldAttribute attribute in attributes)
                    {
                        var attributedFieldRW = new XAttributedFieldRW(rwField, attribute);

                        if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                        {
                            rwFieldList.Add(attributedFieldRW);
                        }
                    }
                }
                else
                {
                    rwFieldList.Add(rwField);
                }
            }

            foreach (var item in properties)
            {
                var rwField = item.Value as IXFieldRW;

                if (rwField == null)
                {
                    continue;
                }

                var attributes = item.Value.PropertyInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                if (attributes != null && attributes.Length != 0)
                {
                    foreach (RWFieldAttribute attribute in attributes)
                    {
                        var attributedFieldRW = new XAttributedFieldRW(rwField, attribute);

                        if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                        {
                            rwFieldList.Add(attributedFieldRW);
                        }
                    }
                }
                else
                {
                    rwFieldList.Add(rwField);
                }
            }

            rwFieldList.Sort((x, y) => x.Order.CompareTo(y.Order));

            foreach (var item in rwFieldList)
            {
                rwFields[item.Name] = item;
            }

            rFields = ArrayHelper.Filter(rwFieldList, item => item.CanRead, item => item);
        }