Exemplo n.º 1
0
 public static void SetDefaultValues(this DynamicModelPropertyInfo info, Dictionary <string, object> propertyNames)
 {
     if (propertyNames.ContainsKey(info.Name))
     {
         info.RemoveAttributes(typeof(DefaultValueAttribute));
         info.AddAttribute(new DefaultValueAttribute(propertyNames[info.Name]));
     }
 }
Exemplo n.º 2
0
 public static void SetCategory(this DynamicModelPropertyInfo info, Dictionary <string, string> propertyNames)
 {
     if (propertyNames.ContainsKey(info.Name))
     {
         info.RemoveAttributes(typeof(BrowsableAttribute));
         info.AddAttribute(new CategoryAttribute(propertyNames[info.Name]));
     }
 }
Exemplo n.º 3
0
 public static bool DXFilter(this DynamicModelPropertyInfo info, IList <Type> baseTypes, Type componentBaseType, Type[] attributes = null)
 {
     if (attributes == null)
     {
         attributes = new[] { typeof(XtraSerializableProperty) }
     }
     ;
     return(Filter(info, componentBaseType, BaseTypes.Union(baseTypes).ToArray(), attributes));
 }
Exemplo n.º 4
0
        static bool FilterCore(DynamicModelPropertyInfo info, Type componentBaseType, IEnumerable <Type> filteredPropertyBaseTypes)
        {
            var behaveLikeValueType = info.PropertyType.BehaveLikeValueType();
            var isBaseViewProperty  = componentBaseType.IsAssignableFrom(info.DeclaringType);
            var propertyBaseTypes   = filteredPropertyBaseTypes as Type[] ?? filteredPropertyBaseTypes.ToArray();
            var filterCore          = propertyBaseTypes.Any(type => type.IsAssignableFrom(info.PropertyType)) || behaveLikeValueType;
            var core = propertyBaseTypes.Any(type => type.IsAssignableFrom(info.DeclaringType)) && behaveLikeValueType;

            return(isBaseViewProperty ? filterCore : core);
        }
Exemplo n.º 5
0
        string GetAttributesCode(DynamicModelPropertyInfo property)
        {
            var attributes = property.GetCustomAttributes(false).OfType <Attribute>().ToList();

            if (property.PropertyType == typeof(string) && !attributes.OfType <LocalizableAttribute>().Any())
            {
                attributes.Add(new LocalizableAttribute(true));
            }
            IEnumerable <string> codeList = attributes.Select(attribute => GetAttributeCode(attribute, property)).Where(attributeCode => !string.IsNullOrEmpty(attributeCode));

            return(codeList.Aggregate <string, string>(null, (current, attributeCode) => current + string.Format("   [{0}]{1}", attributeCode, Environment.NewLine)));
        }
Exemplo n.º 6
0
        public static void CreateValueCalculator(this DynamicModelPropertyInfo info, string expressionPath = null)
        {
            info.AddAttribute(new BrowsableAttribute(false));
//            return;
//            CreateValueCalculatorCore(info);
//            ModelValueCalculatorAttribute modelValueCalculatorAttribute;
//            if (expressionPath != null) {
//                modelValueCalculatorAttribute = new ModelValueCalculatorAttribute(expressionPath);
//                info.AddAttribute(new ModelValueCalculatorWrapperAttribute(modelValueCalculatorAttribute, null));
//            } else {
//                info.RemoveAttributes(typeof(ReadOnlyAttribute));
//                var type = typeof(MapModelValueCalculator);
//                modelValueCalculatorAttribute = new ModelValueCalculatorAttribute(type);
//                info.AddAttribute(new ModelValueCalculatorWrapperAttribute(modelValueCalculatorAttribute, type));
//                info.AddAttribute(new ModelReadOnlyAttribute(typeof(MapModelReadOnlyCalculator)));
//            }
        }
Exemplo n.º 7
0
        string GetPropertyCode(DynamicModelPropertyInfo property, Func <DynamicModelPropertyInfo, bool> filter, Type baseInterface)
        {
            var setMethod = GetSetMethod(property);

            string interfaceName = null;

            if (setMethod == null)
            {
                var reflectedType = property.ReflectedType;
                interfaceName = GetInterfaceName(_assemblyName, reflectedType);
                if (!_createdInterfaces.ContainsKey(property.PropertyType))
                {
                    CreateInterface(property.PropertyType, filter, baseInterface, false, null, interfaceName);
                }
            }

            var propertyCode = string.Format("    {0} {1} {{ get; {2} }}", GetPropertyTypeCode(property, interfaceName), property.Name, setMethod);

            return(GetAttributesCode(property) + propertyCode);
        }
Exemplo n.º 8
0
        string GetPropertyTypeCode(DynamicModelPropertyInfo property, string prefix = null)
        {
            if (property.GetCustomAttributes(typeof(NullValueAttribute), false).Any())
            {
                return(TypeToString(property.PropertyType));
            }
            if (!property.PropertyType.BehaveLikeValueType())
            {
                if (_createdInterfaces.ContainsKey(property.PropertyType))
                {
                    return(_createdInterfaces[property.PropertyType]);
                }
                return(GetInterfaceName(_assemblyName, property.PropertyType, prefix));
            }
            Type propertyType = property.PropertyType;

            if (propertyType != typeof(string) && !propertyType.IsStruct())
            {
                propertyType = typeof(Nullable <>).MakeNullAble(property.PropertyType);
            }
            return(TypeToString(propertyType));
        }
Exemplo n.º 9
0
 static void CreateValueCalculatorCore(DynamicModelPropertyInfo info)
 {
     info.RemoveAttributes(typeof(DefaultValueAttribute));
     info.AddAttribute(new ReadOnlyAttribute(true));
 }
Exemplo n.º 10
0
 public static void CreateValueCalculator(this DynamicModelPropertyInfo info, IModelValueCalculator modelValueCalculator)
 {
     CreateValueCalculatorCore(info);
     info.AddAttribute(new ModelValueCalculatorWrapperAttribute(modelValueCalculator.GetType()));
 }
Exemplo n.º 11
0
 public static bool Filter(this DynamicModelPropertyInfo info, Type componentBaseType, Type[] filteredPropertyBaseTypes, Type[] attributes)
 {
     return(info.IsBrowseable() && info.HasAttributes(attributes) && !ExcludedReservedNames.Contains(info.Name) &&
            FilterCore(info, componentBaseType, filteredPropertyBaseTypes));
 }
Exemplo n.º 12
0
 public static bool DXFilter(this DynamicModelPropertyInfo info, Type componentBaseType, Type[] attributes = null)
 {
     return(DXFilter(info, BaseTypes, componentBaseType, attributes));
 }
Exemplo n.º 13
0
 public static bool DXFilter(this DynamicModelPropertyInfo info, Type[] attributes = null)
 {
     return(info.DXFilter(info.DeclaringType, attributes));
 }
Exemplo n.º 14
0
 public static bool FilterAttributes(this DynamicModelPropertyInfo info, Type[] attributes)
 {
     return(attributes.SelectMany(type => info.GetCustomAttributes(type, false)).Any());
 }
Exemplo n.º 15
0
        string GetAttributeCode(object attribute, DynamicModelPropertyInfo info)
        {
            if (attribute == null)
            {
                return(string.Empty);
            }
            var localizableAttribute = attribute as LocalizableAttribute;

            if (localizableAttribute != null && info.PropertyType == typeof(string))
            {
                string arg = (localizableAttribute).IsLocalizable.ToString(CultureInfo.InvariantCulture).ToLower();
                return(string.Format("{1}({0})", arg, TypeToString(attribute.GetType())));
            }
            if (attribute.GetType() == typeof(CategoryAttribute))
            {
                string arg = ((CategoryAttribute)attribute).Category;
                return(string.Format(@"{1}(""{0}"")", arg, TypeToString(attribute.GetType())));
            }
            if (attribute is RequiredAttribute)
            {
                return(string.Format(@"{0}()", TypeToString(attribute.GetType())));
            }
            var editorAttribute = attribute as EditorAttribute;

            if (editorAttribute != null)
            {
                string arg1 = (editorAttribute).EditorTypeName;
                string arg2 = (editorAttribute).EditorBaseTypeName;
                return(string.Format(@"{2}(""{0}"", ""{1}"")", arg1, arg2, TypeToString(attribute.GetType())));
            }
            var refreshPropertiesAttribute = attribute as RefreshPropertiesAttribute;

            if (refreshPropertiesAttribute != null)
            {
                string arg = TypeToString(refreshPropertiesAttribute.RefreshProperties.GetType()) + "." + refreshPropertiesAttribute.RefreshProperties.ToString();
                return(string.Format(@"{1}({0})", arg, TypeToString(attribute.GetType())));
            }
            var typeConverterAttribute = attribute as TypeConverterAttribute;

            if (typeConverterAttribute != null)
            {
                if (!(typeConverterAttribute).ConverterTypeName.Contains(".Design.") && !(typeConverterAttribute).ConverterTypeName.EndsWith(".Design"))
                {
                    var type = Type.GetType((typeConverterAttribute).ConverterTypeName);
                    if (type != null && type.IsPublic && !type.FullName.Contains(".Design."))
                    {
                        return(string.Format("{1}(typeof({0}))", type.FullName, TypeToString(attribute.GetType())));
                    }
                }
                return(null);
            }
            Type attributeType = attribute.GetType();

            if (attributeType == typeof(DXDescriptionAttribute))
            {
                string description = ((DXDescriptionAttribute)attribute).Description.Replace(@"""", @"""""");
                return(string.Format(@"{1}(@""{0}"")", description, TypeToString(typeof(DescriptionAttribute))));
            }
            if (typeof(DescriptionAttribute).IsAssignableFrom(attributeType))
            {
                string description = ((DescriptionAttribute)attribute).Description.Replace(@"""", @"""""");
                return(string.Format(@"{1}(@""{0}"")", description, TypeToString(typeof(DescriptionAttribute))));
            }
            if (attributeType == typeof(DefaultValueAttribute))
            {
                string value = GetStringValue(((DefaultValueAttribute)attribute).Value);
                return(string.Format(@"System.ComponentModel.DefaultValue({0})", value));
            }
            if (attributeType == typeof(ModelValueCalculatorWrapperAttribute))
            {
                var modelValueCalculatorAttribute = ((ModelValueCalculatorWrapperAttribute)attribute);
                if (modelValueCalculatorAttribute.CalculatorType != null)
                {
                    return(string.Format(@"{0}(typeof({1}))", TypeToString(typeof(ModelValueCalculatorAttribute)), TypeToString(modelValueCalculatorAttribute.CalculatorType)));
                }
                var linkValue = GetStringValue(modelValueCalculatorAttribute.LinkValue);
                return(string.Format(@"{0}({1})", TypeToString(typeof(ModelValueCalculatorAttribute)), linkValue));
            }
            if (attributeType == typeof(ModelReadOnlyAttribute))
            {
                var readOnlyCalculatorType = ((ModelReadOnlyAttribute)attribute).ReadOnlyCalculatorType;
                return(string.Format(@"{0}(typeof({1}))", TypeToString(typeof(ModelReadOnlyAttribute)), TypeToString(readOnlyCalculatorType)));
            }
            if (attributeType == typeof(ReadOnlyAttribute))
            {
                string value = GetStringValue(((ReadOnlyAttribute)attribute).IsReadOnly);
                return(string.Format(@"{1}({0})", value, TypeToString(attribute.GetType())));
            }
            return(string.Empty);
        }
Exemplo n.º 16
0
 object GetSetMethod(DynamicModelPropertyInfo property)
 {
     return(property.PropertyType.BehaveLikeValueType() ? "set;" : null);
 }