0

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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by lqdo
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.