Example #1
0
        public ListPropertyInfoDescriptor(PropertyInfo propertyInfo, PropertyDescriptorProvider provider) : base(provider)
        {
            PropertyInfo = propertyInfo;

            IsReadOnly  = propertyInfo.CanWrite == false;
            Name        = PropertyInfoDescriptor.GetName(propertyInfo, provider);
            DisplayName = PropertyInfoDescriptor.GetDescription(propertyInfo, provider);
            Category    = PropertyInfoDescriptor.GetCategory(propertyInfo, provider);
            Description = PropertyInfoDescriptor.GetDescription(propertyInfo, provider);

            ItemPropertyDescriptor = new ListItemPropertyDescriptor <TCollection, TItem>(provider);

            _getter = PropertyInfoDescriptor.CreatePropertyGetter <TTarget, TCollection>(propertyInfo);
            _setter = propertyInfo.CanWrite ? PropertyInfoDescriptor.CreatePropertySetter <TTarget, TCollection>(propertyInfo) : null;
        }
Example #2
0
 private protected PropertyDescriptor(PropertyDescriptorProvider provider)
 {
     Provider = provider;
 }
 protected CollectionPropertyDescriptor(PropertyDescriptorProvider provider) : base(provider)
 {
 }
Example #4
0
 internal CollectionItemPropertyDescriptor(PropertyDescriptorProvider provider) : base(provider)
 {
 }
Example #5
0
 internal ListItemPropertyDescriptor(PropertyDescriptorProvider provider) : base(provider)
 {
 }
Example #6
0
 public static string GetDescription(PropertyInfo propertyInfo, PropertyDescriptorProvider provider)
 {
     return(propertyInfo.Name);
 }
Example #7
0
 public static string GetCategory(PropertyInfo propertyInfo, PropertyDescriptorProvider provider)
 {
     return(null);
 }
Example #8
0
        public static PropertyDescriptor CreateDescriptor(Type propertyObjectType, PropertyInfo propertyInfo, PropertyDescriptorProvider provider)
        {
            var propertyType    = propertyInfo.PropertyType;
            var genericListType = propertyType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList <>));

            if (genericListType != null)
            {
                var itemType = genericListType.GetGenericArguments().Single();
                var collectionPropertyDescriptorType = typeof(ListPropertyInfoDescriptor <, ,>).MakeGenericType(propertyObjectType, propertyType, itemType);

                return((PropertyDescriptor)Activator.CreateInstance(collectionPropertyDescriptorType, propertyInfo, provider));
            }

            var genericCollectionType = propertyType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection <>));

            if (genericCollectionType != null)
            {
                var itemType = genericCollectionType.GetGenericArguments().Single();
                var collectionPropertyDescriptorType = typeof(CollectionPropertyInfoDescriptor <, ,>).MakeGenericType(propertyObjectType, propertyType, itemType);

                return((PropertyDescriptor)Activator.CreateInstance(collectionPropertyDescriptorType, propertyInfo, provider));
            }

            var propertyDescriptorType = typeof(PropertyInfoDescriptor <,>).MakeGenericType(propertyObjectType, propertyType);

            return((PropertyDescriptor)Activator.CreateInstance(propertyDescriptorType, propertyInfo, provider));
        }