tags:

views:

191

answers:

2

I'm writing a custom config class in C# and .NET 3.5. One of the properties should be of type System.Type. When I run the code I get the error mentioned in the title.

[ConfigurationProperty("alertType", IsRequired = true)]
public Type AlertType
{
    get { return (Type)this["alertType"]; }
    set { this["alertType"] = value; }
}

The config file looks like this:

<add name="Name" pollingInterval="60" alertType="Namespace.ClassName, Company.Project" />

The .net framework is able to cast a string into System.Type, because the configSections of the config file has a type attribute. The question is how do they do it.

Thanks in advanced...

+3  A: 

I think you're looking for Type.GetType Method (String)

Preet Sangha
Sometimes we try to look too hard and the answer is right in front of us :)
Jonas Stawski
A: 

You can try using the TypeNameConverter class. It has two methods you may be interested in:

ConvertToString and ConvertFromString

BFree