Exemplo n.º 1
0
        public IOptionSet Build(ReadOnlyConfigurationOptionModel model, ConfigurationIdentity configIdentity)
        {
            var optionProvider = model.OptionProviderType != null
                ? serviceProvider.GetService(model.OptionProviderType)
                : null;

            return(model.BuildOptionSet(configIdentity, optionProvider));
        }
        private ReadOnlyConfigurationOptionModel BuildReadOptionModel <TOption, TOptionProvider>(Expression <Func <TConfigurationSet, OptionSet <TOption> > > optionSelector, Func <TOption, string> keySelector, Func <TOption, object> descriptionSelector, Func <TOptionProvider, ConfigurationIdentity, IEnumerable <TOption> > optionProvider) where TOption : class, new()
        {
            var propertyInfo = ExpressionHelper.GetPropertyInfo(optionSelector);
            var name         = propertyInfo.Name;
            var type         = typeof(TOption);
            var setter       = (Action <TConfigurationSet, OptionSet <TOption> >)propertyInfo.SetMethod.CreateDelegate(typeof(Action <TConfigurationSet, OptionSet <TOption> >));
            var definition   = new ReadOnlyConfigurationOptionModel <TOption, TConfigurationSet, TOptionProvider>(name, keySelector, descriptionSelector, optionSelector.Compile(), setter, optionProvider);

            ApplyDefaultPropertyDefinitions(definition);

            return(definition);
        }