コード例 #1
0
ファイル: CustomClass.cs プロジェクト: fearog/axecalc
        public override PropertyDescriptorCollection GetProperties( ITypeDescriptorContext context,
										object value, Attribute[] inAttributes )
        {
            //	return TypeDescriptor.GetProperties( value, attributes );
            /*	PropertyDescriptor[] newProps = new PropertyDescriptor[ this.Count ];
                for( int i = 0; i < this.Count; i++ )
                {
                    CustomProperty prop = ( CustomProperty )this[ i ];
                    if( prop.Visible )
                        newProps[ i ] = new CustomPropertyDescriptor( ref prop, attributes );
                }

                return new PropertyDescriptorCollection( newProps );*/
            Type t = value.GetType();
            MemberInfo[] members = t.GetMembers( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public );
            MemberInfo[] interestingMembers = members.Where( member => member.GetCustomAttributes( typeof( DisplayAttribute ), true ).Length > 0 ).ToArray();
            PropertyDescriptor[] newProps = new PropertyDescriptor[ interestingMembers.Length ];
            for( int i = 0; i < interestingMembers.Length; i++ )
            {
                MemberInfo member = interestingMembers[ i ];
                object[] attributes = member.GetCustomAttributes( typeof( DisplayAttribute ), true );
                CustomProperty prop = null;
                if( member.MemberType == MemberTypes.Field )
                {
                    FieldInfo field = ( FieldInfo )member;
                    prop = new CustomProperty( value, field, attributes );
                }
                else if( member.MemberType == MemberTypes.Property )
                {
                    PropertyInfo property = ( PropertyInfo )member;
                    prop = new CustomProperty( value, property, attributes );
                }
                if( prop != null && prop.Visible )
                    newProps[ i ] = new CustomPropertyDescriptor( ref prop, inAttributes );
            }

            return new PropertyDescriptorCollection( newProps );

            /*	foreach( MemberInfo member in t.GetMembers( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public ) )
            {
                object[] attributes = member.GetCustomAttributes( typeof( DisplayAttribute ), true );
                if( attributes.Length == 0 )
                    continue;

                if( member.MemberType == MemberTypes.Field )
                {
                    FieldInfo field = ( FieldInfo )member;
                    Add( new CustomProperty( o, field, attributes ) );
                }
                else if( member.MemberType == MemberTypes.Property )
                {
                    PropertyInfo property = ( PropertyInfo )member;
                    Add( new CustomProperty( o, property, attributes ) );
                }
            }*/
        }
コード例 #2
0
ファイル: CustomClass.cs プロジェクト: fearog/axecalc
 /// <summary>
 /// Add CustomProperty to Collectionbase List
 /// </summary>
 /// <param name="Value"></param>
 public void Add( CustomProperty Value )
 {
     base.List.Add( Value );
 }
コード例 #3
0
ファイル: CustomClass.cs プロジェクト: fearog/axecalc
 public CustomPropertyDescriptor( ref CustomProperty myProperty, Attribute[] attrs )
     : base(myProperty.Name, attrs)
 {
     m_Property = myProperty;
 }