Esempio n. 1
0
 private static void ApplyDefaultPropertyDefinitions(ConfigurationClassCollectionPropertyDefinition model)
 {
     foreach (var kvp in ConfigurationPropertyModelDefinitionFactory.GetDefaultConfigProperties(model.PropertyType))
     {
         model.ConfigurationProperties.Add(kvp.Key, kvp.Value);
     }
 }
Esempio n. 2
0
        private object GetConfigPropertyValueFromInput(JObject source, ConfigurationClassCollectionPropertyDefinition 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);
        }
 private ConfigurationPropertyPayload BuildProperty(ConfigurationClassCollectionPropertyDefinition 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)
     });
 }
Esempio n. 4
0
        private object GetPropertyValue(object source, ConfigurationClassCollectionPropertyDefinition 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);
        }
        private void UpdateOptions(object source, ConfigurationClassCollectionPropertyDefinition model, IEnumerable <ConfigurationSet> configurationSets, ConfigurationIdentity configIdentity)
        {
            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, configurationSets, configIdentity);
            }
        }
Esempio n. 6
0
        /// <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 ConfigurationClassCollectionPropertyBuilder <TConfig> Collection <TModel, TConfig>(this IModelWithProperties <TModel> source, Expression <Func <TModel, ICollection <TConfig> > > expression) where TConfig : new()
        {
            var body = ExpressionHelper.GetExpressionBody(expression);
            ConfigurationPropertyModelBase value;

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

            return(builder);
        }
 internal ConfigurationClassCollectionPropertyBuilder(ConfigurationClassCollectionPropertyDefinition definition) : base(definition)
 {
     this.definition = definition;
 }