Ejemplo n.º 1
0
        private void BuildParameterProvider(INConfigSettings settings, SectionProvider provider, Parameter parameter, PropertyInfo parameterPropertyInfo)
        {
            if (string.IsNullOrEmpty(parameter.TypeName))
            {
                parameter.TypeName = parameterPropertyInfo.PropertyType.AssemblyQualifiedName;
            }
            else if (!parameterPropertyInfo.PropertyType.IsAssignableFrom(Type.GetType(parameter.TypeName, true)))
            {
                throw new InvalidParameterConfiguration(string.Format("Specified type {0} for parameter {1} is not assignable to the property of type {2}", parameter.TypeName, parameter.Name,parameterPropertyInfo.PropertyType.FullName));
            }

            var valueProvider = new ParameterToParameterValueProviderConverter().Convert(parameter, settings);
            provider.ParameterValuesProviders.Add(parameterPropertyInfo.Name, valueProvider);
        }
Ejemplo n.º 2
0
        private void BuildParametersProviders(Section section, INConfigSettings settings, SectionProvider provider, Type sectionType)
        {
            var properties = sectionType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (Parameter parameter in section.Parameters.Values)
            {
                var parameterPropertyInfo = properties.SingleOrDefault(x => x.Name.ToLower() == parameter.Name.ToLower());

                if (parameterPropertyInfo == null && settings.ThrowIfParameterMemberMissing)
                {
                    throw new MemberNotFouldForParameter(parameter);
                }

                this.BuildParameterProvider(settings, provider, parameter, parameterPropertyInfo);
            }
        }
Ejemplo n.º 3
0
        public ISectionProvider Convert(Section section, INConfigSettings settings)
        {
            try
            {
                Type sectionType = Type.GetType(section.TypeName, true);

                var binder = this.GetModelBinderForSection(section, settings);

                var provider = new SectionProvider { SectionType = sectionType, ModelBinder = binder };

                this.BuildParametersProviders(section, settings, provider, sectionType);

                return provider;
            }
            catch (Exception e)
            {
                throw new SessionToProviderConvertionFailed(section, e);
            }
        }