3

web.configに次のノードがあります

<parameter value="100" type="System.Int64, mscorlib" />

これは次の ConfigurationProperty に読み込まれます

public class ParameterElement : ConfigurationElement
{
    [ConfigurationProperty("type", IsRequired = false, DefaultValue = "System.String, mscorlib")]
    [TypeConverter(typeof (TypeNameConverter))]
    public Type Type
    {
        get { return (Type) this["type"]; }
        set { this["type"] = value; }
    }

    [ConfigurationProperty("value", IsRequired = true)]
    public object Value
    {
        get { return ... ? }
        set { this["value"] = value; }
    }
}

これは、ノードに設定した Type を正しく確立していますが、その型の値を返すにはどうすればよいですか? 私が試したことはすべて、次の例外を返します。

タイプ「オブジェクト」のプロパティ「値」の文字列との間の変換をサポートするコンバーターが見つかりません。

4

1 に答える 1