コード例 #1
0
        public void LoadConfiguration([NotNull] EntityConfiguration config)
        {
            LoadEntityConfiguration(config);

            // Loading property configuration.
            var ownProps = config.EntityType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance).ToList();
            var props    = config.EntityType.GetProperties().ToList();

            var propsWithoutDuplicates = props.GroupBy(p => p.Name, (name, duplicates) =>
                                                       duplicates
                                                       .Select(dp => new { IsOwn = ownProps.Contains(dp), Prop = dp })
                                                       .OrderByDescending(dp => dp.IsOwn ? 1 : 0)
                                                       .Select(dp => dp.Prop)
                                                       .FirstOrDefault()
                                                       ).ToList();

            if (propsWithoutDuplicates.Count < props.Count)
            {
                var duplicates = props.Where(p => !propsWithoutDuplicates.Contains(p)).ToList();
                props = propsWithoutDuplicates;
            }

            foreach (var prop in props)
            {
                try
                {
                    var propConfig = new PropertyConfiguration(config.EntityType);
                    LoadPropertyConfiguration(prop, propConfig);
                    config.Properties.Add(prop.Name, propConfig);
                }
                catch
                {
                    throw;
                }
            }
        }
コード例 #2
0
        private static void LoadChangeLoggingPropertyConfiguration(PropertyInfo propInfo, PropertyConfiguration propConfig)
        {
            propConfig.LogChanges = false;

            /* todo: review ABP logging and uncomment/remove
             * var att = ReflectionHelper.GetPropertyAttribute<LogChangesAttribute>(propInfo);
             * if (att == null)
             * {
             *  propConfig.LogChanges = false;
             * }
             * else
             * {
             *  propConfig.LogChanges = true;
             *  propConfig.FixedDescriptionOnChange = att.FixedDescription;
             *  propConfig.DetailPropertyOnChange = att.DetailPropertyInDescription;
             *  propConfig.DetailOldValueOnChange = att.DetailOldValueInDescription;
             *  propConfig.DetailNewValueOnChange = att.DetailNewValueInDescription;
             *  propConfig.AuditLogEntryNamespaceOnChange = att.Namespace;
             * }
             */
        }
コード例 #3
0
        private static void LoadPropertyConfiguration(PropertyInfo prop, PropertyConfiguration propConfig)
        {
            propConfig.PropertyInfo = prop;
            propConfig.GeneralType  = GetGeneralDataType(prop);
            propConfig.Category     = prop.GetAttribute <CategoryAttribute>()?.Category;

            switch (propConfig.GeneralType)
            {
            case GeneralDataType.Numeric:
            case GeneralDataType.ReferenceList:
                var refListAtt = ReflectionHelper.GetPropertyAttribute <ReferenceListAttribute>(prop, true);
                if (refListAtt == null)
                {
                    if (prop.PropertyType.IsEnum && prop.PropertyType.HasAttribute <ReferenceListAttribute>())
                    {
                        refListAtt = prop.PropertyType.GetAttribute <ReferenceListAttribute>();
                    }
                    else
                    {
                        var underlyingType = Nullable.GetUnderlyingType(prop.PropertyType);
                        if (underlyingType != null && underlyingType.IsEnum &&
                            underlyingType.HasAttribute <ReferenceListAttribute>())
                        {
                            refListAtt = underlyingType.GetAttribute <ReferenceListAttribute>();
                        }
                    }
                }

                if (refListAtt != null)
                {
                    propConfig.ReferenceListName        = refListAtt.ReferenceListName;
                    propConfig.ReferenceListNamespace   = refListAtt.Namespace;
                    propConfig.ReferenceListOrderByName = refListAtt.OrderByName;
                }
                break;

            case GeneralDataType.Enum:
                var enumType = prop.PropertyType;
                if (enumType.IsNullable())
                {
                    enumType = Nullable.GetUnderlyingType(prop.PropertyType);
                }
                propConfig.EnumType = enumType;
                break;

            case GeneralDataType.MultiValueReferenceList:
                var mvRefListAtt = ReflectionHelper.GetPropertyAttribute <MultiValueReferenceListAttribute>(prop, true);
                propConfig.ReferenceListName      = mvRefListAtt.ReferenceListName;
                propConfig.ReferenceListNamespace = mvRefListAtt.Namespace;
                break;

            case GeneralDataType.EntityReference:
                propConfig.EntityReferenceType = prop.PropertyType;
                break;

            default:
                break;
            }

            propConfig.Label = GetPropertyLabel(prop);

            LoadChangeLoggingPropertyConfiguration(prop, propConfig);
        }