0

I have an interface

public interface IConfig
{
    string name { get; set; }
    string address { get; set; }
    int phone { get; set; }

    List<string> children { get; set; }
}

Here is my config file that has only three app settings not four like i have in interface.

<add key="name" value="abc" />
<add key="address" value="100 Norin Street" />
<add key="phone" value="709-111-111111" />

Now on startup I am using DictionaryAdapterFactory to fillin the app.config file values. I am successfully getting values of app.config here.

private readonly IConfig _config;
private readonly DictionaryAdapterFactory _factory;
_factory = new DictionaryAdapterFactory();
_config = _config.GetAdapter<IConfig>(ConfigurationManager.AppSettings);

now at run time I need to fill in the value of children which is List type. But i am getting null exception. Why?

//loop
_config.children.Add(item.values);

What is the problem here?

4

3 に答える 3

4

リストの初期化がどこかにありませんか?

_config.children = new List<string>()
于 2012-04-13T20:01:19.467 に答える
0

以下のようになりますか?

_config.children.AddRange(item.values); 

もちろん、初期化も必要です。

_config.children = new List<string>();
于 2012-04-13T20:16:06.527 に答える
0

AppSettings の phone 値は int にキャストできませんが、インターフェイスで「Phone」を int として定義しました。文字列に変更します:

  string phone { get; set; }
于 2013-11-27T23:43:09.860 に答える