/// <summary>
        /// Add the  fields of an object
        /// </summary>
        private static void AddTypeFields(IReflect type, Attribute[] attributes, PropertyDescriptorCollection fields, ICollection <string> addedMemberNames)
        {
            if ((type == typeof(ArrayList)) ||
                (type == typeof(Hashtable)) ||
                (type == typeof(SortedList)))
            {
                return;
            }

            // get all instance FieldInfos
            var fieldInfos = type.GetFields(_bindingFlags);

            var filtering = attributes != null && attributes.Length > 0;

            foreach (var field in fieldInfos.Where(field => !addedMemberNames.Contains(field.Name)))
            {
                // this one made it in the list...
                addedMemberNames.Add(field.Name);
                var fieldDesc = new FieldPropertyDescriptor(field);
                if (!filtering || fieldDesc.Attributes.Contains(attributes))
                {
                    fields.Add(fieldDesc);
                }
            }
        }
コード例 #2
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            bool filtering = (attributes != null && attributes.Length > 0);
            PropertyDescriptorCollection props = cachedPropertyDescriptors;
            FilterCache cache = cachedFilter;

            // Use a cached version if possible
            if (filtering && cache != null && cache.IsValid(attributes))
            {
                return(cache.FilteredProperties);
            }
            else if (!filtering && props != null)
            {
                return(props);
            }

            // Create the property collection and filter
            props = new PropertyDescriptorCollection(null);
            foreach (PropertyDescriptor prop in
                     TypeDescriptor.GetProperties(
                         this, attributes, true))
            {
                props.Add(prop);
            }
            foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                FieldPropertyDescriptor fieldDesc = new FieldPropertyDescriptor(field);
                if (!filtering || fieldDesc.Attributes.Contains(attributes))
                {
                    props.Add(fieldDesc);
                }
            }

            // Store the computed properties
            if (filtering)
            {
                cache                    = new FilterCache();
                cache.Attributes         = attributes;
                cache.FilteredProperties = props;
                cachedFilter             = cache;
            }
            else
            {
                cachedPropertyDescriptors = props;
            }

            return(props);
        }
コード例 #3
0
ファイル: Class2.cs プロジェクト: lanicon/Cinchoo
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            // Retrieve cached properties and filtered properties
            bool        filtering = attributes != null && attributes.Length > 0;
            FilterCache cache     = _provider._filterCache;
            PropertyDescriptorCollection props = _provider._propCache;

            // Use a cached version if we can
            if (filtering && cache != null && cache.IsValid(attributes))
            {
                return(cache.FilteredProperties);
            }
            else if (!filtering && props != null)
            {
                return(props);
            }

            // Otherwise, create the property collection
            props = new PropertyDescriptorCollection(null);
            foreach (PropertyDescriptor prop in base.GetProperties(attributes))
            {
                props.Add(prop);
            }
            foreach (FieldInfo field in _objectType.GetFields())
            {
                FieldPropertyDescriptor fieldDesc = new FieldPropertyDescriptor(field);
                if (!filtering || fieldDesc.Attributes.Contains(attributes))
                {
                    props.Add(fieldDesc);
                }
            }

            // Store the updated properties
            if (filtering)
            {
                cache = new FilterCache();
                cache.FilteredProperties = props;
                cache.Attributes         = attributes;
                _provider._filterCache   = cache;
            }
            else
            {
                _provider._propCache = props;
            }

            // Return the computed properties
            return(props);
        }
コード例 #4
0
    public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
    {
        List <PropertyDescriptor> properties = new List <PropertyDescriptor>(base.GetProperties(context, value, attributes).OfType <PropertyDescriptor>());

        if (value != null)
        {
            foreach (FieldInfo field in value.GetType().GetFields())
            {
                FieldPropertyDescriptor fieldDesc = new FieldPropertyDescriptor(field);
                {
                    properties.Add(fieldDesc);
                }
            }
        }
        return(new PropertyDescriptorCollection(properties.ToArray()));
    }
コード例 #5
0
            public override bool Equals(object obj)
            {
                FieldPropertyDescriptor other = obj as FieldPropertyDescriptor;

                return(other != null && other._field.Equals(_field));
            }
コード例 #6
0
		public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			// Retrieve cached properties and filtered properties
			bool filtering = attributes != null && attributes.Length > 0;
			FilterCache cache = _provider._filterCache;
			PropertyDescriptorCollection props = _provider._propCache;

			// Use a cached version if we can
			if (filtering && cache != null && cache.IsValid(attributes)) return cache.FilteredProperties;
			else if (!filtering && props != null) return props;

			// Otherwise, create the property collection
			props = new PropertyDescriptorCollection(null);
			/*foreach (PropertyDescriptor prop in base.GetProperties(attributes))
			{
				props.Add(prop);
			}*/
            foreach (FieldInfo field in _objectType.GetFields(BindingFlags.Public | BindingFlags.Instance))
			{
				FieldPropertyDescriptor fieldDesc = new FieldPropertyDescriptor(field);
				if (!filtering || fieldDesc.Attributes.Contains(attributes)) props.Add(fieldDesc);
			}

			// Store the updated properties
			if (filtering)
			{
				cache = new FilterCache();
				cache.FilteredProperties = props;
				cache.Attributes = attributes;
				_provider._filterCache = cache;
			}
			else _provider._propCache = props;

			// Return the computed properties
			return props;
		}