示例#1
0
        public FieldDescriptor Create(PropertyInfo property)
        {
            var displayAttribute = PropertyAttributeInheritor.GetFor <DisplayAttribute>(property).FirstOrDefault();

            var autoGenerate = displayAttribute?.GetAutoGenerateField() ?? true;
            var group        = displayAttribute?.GetGroupName();
            var label        = displayAttribute?.GetName();

            var type       = property.PropertyType;
            var isSortable = false;

            if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(IEnumerable <>) || type.GetGenericTypeDefinition() == typeof(List <>) || type.GetGenericTypeDefinition() == typeof(IList <>)))
            {
                type       = type.GetGenericArguments().Single();
                isSortable = true;
            }

            var uiHints = PropertyAttributeInheritor.GetFor <UIHintAttribute>(property)
                          .Select(a => a.UIHint)
                          .Select(uiHint => UIHintParser.Parse(uiHint))
                          .ToList()
                          .AsReadOnly();

            return(new FieldDescriptor(property.Name, type, uiHints, label, isSortable, autoGenerate, group));
        }
示例#2
0
        public FieldDescriptor Create(PropertyInfo property)
        {
            var displayAttribute = PropertyAttributeInheritor.GetFor <DisplayAttribute>(property).FirstOrDefault();

            var autoGenerate = displayAttribute?.GetAutoGenerateField() ?? true;
            var group        = displayAttribute?.GetGroupName();
            var label        = displayAttribute?.GetName();

            var type       = property.PropertyType;
            var isSortable = false;

            if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(IEnumerable <>) || type.GetGenericTypeDefinition() == typeof(List <>) || type.GetGenericTypeDefinition() == typeof(IList <>)))
            {
                type       = type.GetGenericArguments().Single();
                isSortable = true;
            }

            var uiHints = new List <UIHint>();

            foreach (var uiHintAttribute in PropertyAttributeInheritor.GetFor <UIHintAttribute>(property))
            {
                var uiHint = uiHintAttribute.UIHint;

                foreach (var replacer in ComposableProvider.GetAll <IUIHintReplacer>())
                {
                    uiHint = replacer.Replace(uiHint);
                }

                uiHints.Add(UIHintParser.Parse(uiHint));
            }

            return(new FieldDescriptor(property.Name, type, uiHints.AsReadOnly(), label, isSortable, autoGenerate, group));
        }