private static void ApplyDefaultPropertyDefinitions(ConfigurationCollectionPropertyDefinition model)
 {
     foreach (var kvp in ConfigurationPropertyModelDefinitionFactory.GetDefaultConfigProperties(model.PropertyType))
     {
         model.ConfigurationProperties.Add(kvp.Key, kvp.Value);
     }
 }
 private static void ApplyDefaultPropertyDefinitions(ConfigurationCollectionPropertyDefinition model)
 {
     foreach (PropertyInfo writeProperty in model.PropertyType.GetProperties().Where(prop => prop.CanWrite))
     {
         model.ConfigurationProperties.Add(writeProperty.Name, ConfigurationPropertyModelDefinitionFactory.Build(writeProperty, model.PropertyType));
     }
 }
 private ConfigurationPropertyPayload BuildProperty(ConfigurationCollectionPropertyDefinition value)
 {
     return(new ConfigurationPropertyPayload
     {
         PropertyName = value.ConfigurationPropertyName.ToLowerCamelCase(),
         PropertyDisplayName = value.PropertyDisplayName,
         PropertyType = ConfigurationPropertyType.Collection,
         PropertyDescription = value.PropertyDescription,
         ChildProperty = BuildProperties(value.ConfigurationProperties)
     });
 }
        private object GetConfigPropertyValueFromInput(JObject source, ConfigurationCollectionPropertyDefinition propertyModel)
        {
            var collectionBuilder = propertyModel.GetCollectionBuilder();

            foreach (var item in source.GetValue(propertyModel.ConfigurationPropertyName.ToLowerCamelCase()))
            {
                var config = collectionBuilder.IntializeNewItem();
                config = UpdateObject(config, (JObject)item, propertyModel.ConfigurationProperties);
                collectionBuilder.Add(config);
            }
            return(collectionBuilder.Collection);
        }
        private object GetConfigPropertyValueFromInput(JObject source, ConfigurationCollectionPropertyDefinition propertyModel, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> requiredConfigurationSets)
        {
            var collectionBuilder = propertyModel.GetCollectionBuilder();

            foreach (var item in source.GetValue(propertyModel.ConfigurationPropertyName.ToLowerCamelCase()))
            {
                var config = propertyModel.NewItemInstance();
                config = UpdateObject(config, (JObject)item, propertyModel.ConfigurationProperties, configIdentity, requiredConfigurationSets);
                collectionBuilder.Add(config);
            }
            return(collectionBuilder.Collection);
        }
Esempio n. 6
0
 private ConfigurationPropertyPayload BuildProperty(ConfigurationCollectionPropertyDefinition value, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> requiredConfigurationSets)
 {
     return(new ConfigurationPropertyPayload
     {
         PropertyName = value.ConfigurationPropertyName.ToLowerCamelCase(),
         PropertyDisplayName = value.PropertyDisplayName,
         PropertyType = ConfigurationPropertyType.Collection,
         PropertyDescription = value.PropertyDescription,
         KeyPropertyName = value?.KeyPropertyName?.ToLowerCamelCase(),
         ChildProperty = BuildProperties(value.ConfigurationProperties, configIdentity, requiredConfigurationSets)
     });
 }
        private object GetPropertyValue(object source, ConfigurationCollectionPropertyDefinition propertyModel)
        {
            var collection = propertyModel.GetPropertyValue(source) as IEnumerable ?? new List <object>();

            var result = new List <object>();

            foreach (var item in collection)
            {
                var itemValue = BuildObject(item, propertyModel.ConfigurationProperties);
                result.Add(itemValue);
            }

            return(result);
        }
Esempio n. 8
0
        private void UpdateOptions(object source, ConfigurationCollectionPropertyDefinition model)
        {
            var items = model.GetPropertyValue(source) as IEnumerable;

            if (items == null)
            {
                var collectionBuilder = model.GetCollectionBuilder();
                model.SetPropertyValue(source, collectionBuilder.Collection);
                return;
            }
            foreach (var item in items)
            {
                UpdateOptions(item, model.ConfigurationProperties);
            }
        }
        /// <summary>
        /// Gets ConfigurationCollectionPropertyBuilder for a collection
        /// </summary>
        /// <typeparam name="TModel">Property parent Type</typeparam>
        /// <typeparam name="TConfig">Type of object in collection</typeparam>
        /// <param name="source">model with property</param>
        /// <param name="expression">collection selector</param>
        /// <returns>ConfigurationCollectionPropertyBuilder for selected property</returns>
        public static ConfigurationCollectionPropertyBuilder <TConfig> Collection <TModel, TConfig>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ICollection <TConfig> > > expression) where TConfig : new()
        {
            var body = GetExpressionBody(expression);
            ConfigurationPropertyModelBase value;

            if (!source.ConfigurationProperties.TryGetValue(body.Member.Name, out value) || !(value is ConfigurationCollectionPropertyDefinition <TConfig>))
            {
                var type = body.Type;
                if (type == typeof(ICollection <TConfig>))
                {
                    type = typeof(List <TConfig>);
                }
                var definition = new ConfigurationCollectionPropertyDefinition <TConfig>(body.Member.Name, typeof(TConfig), typeof(TModel), type);
                ApplyDefaultPropertyDefinitions(definition);
                value = definition;
                source.ConfigurationProperties[value.ConfigurationPropertyName] = value;
            }
            var builder = new ConfigurationCollectionPropertyBuilder <TConfig>((ConfigurationCollectionPropertyDefinition)value);

            return(builder);
        }
 private string GetPropertyType(ConfigurationCollectionPropertyDefinition definition)
 {
     return(ConfigurationPropertyType.Collection);
 }
Esempio n. 11
0
 internal ConfigurationCollectionPropertyBuilder(ConfigurationCollectionPropertyDefinition definition)
 {
     this.definition = definition;
 }