Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetConfig <T>() where T : ConfigurationSection, new()
        {
            DotNetConfigFileAttribute attribute = AttributeHelper.GetConfigAttribute <T, DotNetConfigFileAttribute>();

            if (attribute == null)
            {
                ConfigThrowHelper.ThrowConfigException(
                    R.ConfigError_NoConfigAttribute, typeof(T).FullName, typeof(DotNetConfigFileAttribute).FullName);
            }

            return(GetConfig <T>(attribute.SectionName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 用正在属性化的DotNet配置文件位置特性初始化 <see cref="ConfigFileSectionAttribute"/> 类的新实例。
        /// </summary>
        /// <param name="sectionGroupType">DotNet配置结点组类型。</param>
        /// <param name="sectionName">DotNet配置结点名。。</param>
        public DotNetConfigFileAttribute(string fileName, string sectionName, Type sectionGroupType)
            : base(fileName)
        {
            this.sectionName = sectionName;
            this.FileName    = fileName;

            DotNetConfigFileAttribute attribute =
                Attribute.GetCustomAttribute(sectionGroupType, typeof(DotNetConfigFileAttribute)) as DotNetConfigFileAttribute;

            if (attribute == null)
            {
                ConfigThrowHelper.ThrowConfigException(
                    R.ConfigError_NoConfigAttribute, sectionGroupType.FullName, typeof(DotNetConfigFileAttribute).FullName);
            }

            this.sectionGroupType = sectionGroupType;
        }