예제 #1
0
 public static void DefineFacets(IEnumerable <PropertyFacetDefinition> propertyFacetDefinitions)
 {
     FriendlyNameFacet   = new PropertyFacet <string>(nameof(FriendlyNameFacet), null, source => source.Name.SmartSeparate());
     IsRequiredFacet     = new PropertyFacet <bool>(nameof(IsRequiredFacet), false, source => !source.IsNullable);
     ReadOnlyInEditFacet = new PropertyFacet <bool>(nameof(ReadOnlyInEditFacet), false, null);
     ReflectionHelper.FillFacetsDictionary <PropertyMetadata>(_facets, propertyFacetDefinitions, typeof(PropertyFacet <>));
 }
예제 #2
0
 public MetadataModel(MetadataBundle bundle)
 {
     AdditionalBehaviors = bundle.AdditionalBehaviors.ToDictionary(x => x.Name,
                                                                   x => new AdditionalBehaviorMetadata
     {
         Definition = x.Definition,
         Name       = x.Name
     });
     PropertyDefaults = bundle.PropertyFacetDefaultValues
                        .GroupBy(x => x.GeneralUsageCategory.Name)
                        .Select(x => new PropertyGeneralUsageCategory
     {
         Name     = x.Key,
         Defaults = x
                    .Select(y => PropertyFacet.Create(y))
                    .ToDictionary(y => y.Name, y => y)
     }).ToDictionary(x => x.Name, x => x as IPropertyGeneralUsageCategory);
     EntityTypes = bundle.EntityTypes.Select(x =>
                                             new EntityMetadata
     {
         Name       = x.Name,
         SchemaName = x.SchemaName,
         EntityGeneralUsageCategoryId = x.GeneralUsageCategoryId,
         SingularTitle   = x.SingularTitle,
         PluralTitle     = x.PluralTitle,
         DisplayNamePath = x.DisplayNamePath,
         CodePath        = x.CodePath,
         PrimaryKeyPath  = x.Properties?.FirstOrDefault(p => p.GeneralUsageCategoryId == 2)?.Name,                        //TODO: Unsafe
         Properties      = x.Properties?.Select(p =>
                                                new PropertyMetadata
         {
             Name           = p.Name,
             GeneralUsage   = p.GeneralUsageCategory.Name,
             DataType       = p.DataType.Identifier,
             EntityTypeName = p.DataEntityType?.Name,
             LocalFacets    = p.PropertyFacetValues
                              ?.Select(v => PropertyFacet.Create(v))
                              ?.ToDictionary(v => v.Name, v => v),
             ForeignKeyName      = p.ForeignKeyProperty?.Name,
             InversePropertyName = p.InverseProperty?.Name,
             Title        = p.Title,
             IsNullable   = p.IsNullable,
             IsExpression = p.IsExpression,
             Behaviors    = p.PropertyBehaviors?.Select(x => new PropertyBehaviorMetadata
             {
                 BehaviorName = x.AdditionalBehavior.Name,
                 Parameters   = x.Parameters
             })?.ToList()
         }).ToDictionary(p => p.Name, p => p)
     }).ToDictionary(x => x.Name, x => x as IEntityTypeMetadataModel);
 }