public override void ModelLoaded(IPropertyDefinition propertyDefinition) { var untypedItemsData = propertyDefinition.PropertyBag[PropertyItems]; if (untypedItemsData is PropertyBag) { var propertyBagItemsData = (PropertyBag)untypedItemsData; if ((propertyBagItemsData["type"] as string).IsNullOrEmpty()) { throw new ModelLoadingException($"When using inline property definitions, the property type is mandatory (on {propertyDefinition})."); } var itemsType = propertyDefinition.GetValueTypeOrEntityDefinition(propertyBagItemsData["type"] as string); if (itemsType == null) { throw new ModelLoadingException( $"Unable to find an entity or a value type named {propertyBagItemsData["type"]} (on {propertyDefinition})."); } propertyBagItemsData["name"] = propertyDefinition.Name + "_" + PropertyItems; propertyBagItemsData["description"] = $"Items for {propertyDefinition}"; var itemsPropertyDefinition = PropertyDefinitionFactory.Create(propertyDefinition.EntityDefinition, itemsType, propertyBagItemsData); itemsPropertyDefinition.PropertyType.ModelLoaded(itemsPropertyDefinition); propertyDefinition.AdditionalProperties[PropertyItems] = itemsPropertyDefinition; return; } if (untypedItemsData is string) { var itemsType = propertyDefinition.GetValueTypeOrEntityDefinition((string)untypedItemsData); if (itemsType == null) { throw new ModelLoadingException( $"Unable to find an entity or a value type named {untypedItemsData} (on {propertyDefinition})."); } var itemsPropertyBag = new PropertyBag { ["name"] = propertyDefinition.Name + "_" + PropertyItems, ["description"] = $"Items for {propertyDefinition}" }; var itemsPropertyDefinition = PropertyDefinitionFactory.Create(propertyDefinition.EntityDefinition, itemsType, itemsPropertyBag); itemsPropertyDefinition.PropertyType.ModelLoaded(itemsPropertyDefinition); propertyDefinition.AdditionalProperties[PropertyItems] = itemsPropertyDefinition; return; } throw new ModelLoadingException( $"An array must have an item property that points to either a value type or an entity (on {propertyDefinition})."); }
private IEnumerable <IPropertyDefinition> MapProperties(IEntityDefinition entityDefinition, PropertyBag[] properties) { var propertyDefinitions = properties .Safe() .Select(property => PropertyDefinitionFactory.Create(entityDefinition, _valueTypeFactory.GetValueType(property["type"] as string), property)) .ToList(); if ((entityDefinition.EntityType != EntityType.None) && !propertyDefinitions.Any(x => x.Name.SafeOrdinalEquals(MetaConstants.IdProperty))) { propertyDefinitions.Add(new DefaultIdPropertyDefinition(entityDefinition, _valueTypeFactory.GetValueType("uuid"))); } return(propertyDefinitions); }