示例#1
0
        internal ConfigurationSection(IConfigurationValueCollection values, string sectionKey)
        {
            this.Descriptor = new ConfigurationSectionDescriptor <T>(sectionKey);
            this.configurationInterceptor = new ConfigurationInterceptor(this.Descriptor, values);
            // if this is a CVC base implementation, we should ensure defaults.
            (values as ConfigurationValueCollection)?.EnsureSectionDefaults(this.Descriptor);
            this.ValueCollection = values;

            this.Configuration =
                ConfigurationDescriptorCache
                .GetProxyGenerator()
                .CreateInterfaceProxyWithoutTarget <T>(new ConfigurationCircularInterceptor <T>(this),
                                                       configurationInterceptor);
        }
        internal InputConfigurationSection(InputTemplateCircularInterceptor <T> interceptor,
                                           InputTemplateInterceptor <T> inputTemplate)
        {
            this.Descriptor = new ConfigurationSectionDescriptor <T>(typeof(T).Name);
            ProxyGenerator generator = new ProxyGenerator();
            var            options   = from prop in typeof(T).GetProperties()
                                       let attr = prop.GetCustomAttribute <ConfigurationOptionAttribute>()
                                                  where attr != null
                                                  let name = prop.Name
                                                             let metadata = prop.GetCustomAttributes <CustomMetadataAttribute>()
                                                                            select new ConfigurationOptionDescriptor(attr, metadata, name) as IConfigurationOptionDescriptor;

            this.Options = options.ToList();
            // todo: fix this.
            this.ValueCollection          = new ConfigurationValueCollection();
            this.configurationInterceptor = new ConfigurationInterceptor(this.Descriptor, this.ValueCollection);
            this.Configuration            =
                generator.CreateInterfaceProxyWithoutTarget <T>(interceptor,
                                                                configurationInterceptor, inputTemplate);
        }