David Horák
David Horák

Reputation: 5565

C# unknown types

public T Deserialize<T>(string input);

and object

object deserialzeType;

how i can parse it class type from object into into this function ?

Deserialize<deserialzeType>("text");

I am trying deserealize HttpWebResponse into concrete type, but i want to do dynamically. I want call function GetResopnse and in input parameter, class for deserialing into. Something like this:

ParseIntoClass result = HttpResponse.GetRespond(ParseIntoClass);

Upvotes: 0

Views: 243

Answers (1)

porusan
porusan

Reputation: 918

As Joel said, when using generic types, you cannot dynamically set the type for objects at run time.

In your snippet

Deserialize<deserialzeType>("text");

"deserializeType" must be a Type recognized by the compiler - it cannot be an Type variable that you've set to be some type recognized by the compiler.

Upvotes: 1

Related Questions