C# 尝试使用XYZ pcmsim=(XYZ)appConfig.GetSection(“XYZ”)获取节时出错;
需要解释以下MSDN链接上的配置节类型 对以下章节有异议C# 尝试使用XYZ pcmsim=(XYZ)appConfig.GetSection(“XYZ”)获取节时出错;,c#,config,C#,Config,需要解释以下MSDN链接上的配置节类型 对以下章节有异议 <configuration> <configSections> <section name="CustomSection" type="ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample" allowDefinition="Everywhere" allow
<configuration>
<configSections>
<section name="CustomSection" type="ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample"
allowDefinition="Everywhere" allowExeDefinition="MachineToApplication"
restartOnExternalChanges="true" />
</configSections>
<CustomSection fileName="override.txt" alias="alias.txt"
maxUsers="1000" maxIdleTime="00:05:00" />
</configuration>
节名称有一个类型。我需要知道逗号前后的名称应该使用什么。我打开了解决方案资源管理器并查看了程序集的引用。我假设引用和类型必须匹配。我的应用程序和许多嵌套类以及MSDN网页没有提供有关如何在嵌套类中引用对象的良好信息。为
类型
属性指定的值表示CustomSection类型的程序集限定名
从
类型的程序集限定名由类型名组成,
包括其名称空间,后跟逗号,后跟显示
程序集的名称
ConfigurationPropertyExample.CustomSection,ConfigurationPropertyExample
从左到右包括
命名空间:ConfigurationPropertyExample
类型/类名:CustomSection
包含CustomType
类型:ConfigurationPropertyExample
(大多数情况下,这将是不带(.dll或.exe)文件扩展名的程序集文件名。)
使用Type.AssemblyQualifiedName
属性检索类型程序集限定名
var assemblyQualifiedName = typeof(CustomSection).AssemblyQualifiedName;
返回的值可能不仅仅包括名称空间、类和程序集,
如版本、区域性和公钥令牌(请参阅),例如
ConfigurationPropertyExample.CustomSection,ConfigurationPropertyExample,版本=1.0.0.0,区域性=中性,PublicKeyToken=null
大多数情况下,不必在配置类型
定义中包含最后这些,除非您正在使用
对于嵌套类,程序集限定名称中的嵌套类前面将有一个加号(+
)
var assemblyQualifiedName = typeof(CustomSection).AssemblyQualifiedName;
如果将CustomSection
类定义为类Settings
的嵌套类,则其程序集限定名称将为ConfigurationPropertyExample.Settings+CustomSection,ConfigurationPropertyExample
namespace ConfigurationPropertyExample
{
public class Settings
{
public sealed class CustomSection : ConfigurationSection
{
// ...
}
}
}