我需要另外一套眼睛来解决这个问题.我得到了一个
ConfigurationErrorsException未处理"属性'exportClientSettings'不是ConfigurationElement."
我打电话时会抛出异常 ExportClientConfiguration.GetSection();
这是我的代码:
App.config中
<configSections>
<section name="exportClientConfiguration" type="ClientConversionUtilityBroker.ConfigurationModels.ExportClientPathConfiguration.ExportClientConfiguration, ClientConversionUtilityBroker"/>
</configSections>
<exportClientConfiguration>
<exportClientSettings>
<exportClientSetting name="Example" Path="\\Example\Path" />
</exportClientSettings>
</exportClientConfiguration>
Run Code Online (Sandbox Code Playgroud)
C#代码
/// <summary>
/// The export client configuration section.
/// </summary>
public class ExportClientConfiguration : ConfigurationSection, IExportClientConfiguration
{
private const string ExportClientSettingsCollectionName = "exportClientSettings";
/// <summary>
/// Gets the export client configuration items.
/// </summary>
/// <value>
/// The export client configuration items.
/// </value>
[ConfigurationProperty(ExportClientSettingsCollectionName, IsDefaultCollection = true)]
public IEnumerable<ExportClientSettings> ExportClientConfigurationItems
{
get { return base[ExportClientSettingsCollectionName] as ExportClientSettingsCollection; } …
Run Code Online (Sandbox Code Playgroud) 我有一个扩展方法ParseItemsToIntegers
,它是一个字符串数组的扩展方法,我正在使用它,就像使用任何扩展一样.
var ids = ChkBoxSelected.ParseItemsToIntegers();
Run Code Online (Sandbox Code Playgroud)
我观察到的行为是,如果ChkBoxSelected
为null,它将毫无问题地调用扩展方法,但是在扩展方法中它会在空字符串数组上抛出空引用异常.
它是如何解决null上的扩展方法的?
为什么ChkBoxSelected
在调用扩展方法时它没有抛出空引用异常?