Im am using serialization and deserialisation to read and store settings in a xml file. I have het created a generic class because I want to store different kind of settings in different kind of xml files. Is it possible to instantiate the type of the generic class within that class?

example:

class Example<T>
{
        T obj;

        public Example()
        {
            obj = new T();
        }
}

static void Main()
{
            Example<SomeSettings> example = new    Example<SomeSettings>();
}

I know the code above is not working but i hope it explains what i want. I als know i can use a where statement like...

class Example<T> where T : SomeSetting, new()

But this this is not working for me because the generic class is used by multiple types.

Please advise me

XML Serialization/Deserialization : It serialize only public properties and fields and does not preserve type fidelity.

thx for the reply but thats not what i ment.

I want to create an object of the class that is given as argument in the generic class. I dont want to serialize that type into xml but the properties.

The example in the opening post is shows the thing i want to do. I have alterd it a little so I can demonstrate the way i want to acces the my settingsclass

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.