Ragesh Puthiyedath Raju
Ragesh Puthiyedath Raju

Reputation: 3939

The type or namespace name 'T' could not be found

I try to implement LinkedIn Authentication in my VS 2010 MVC3 application. I refer source

code in a blog website. But i found there is a error occurred in while building the code.

Please see this below image.

enter image description here

There is any reference needed in this 'T' object.

Please help.

UPDATE QUESTION

I update my question as per @StuartLC

enter image description here

Upvotes: 1

Views: 8894

Answers (3)

StuartLC
StuartLC

Reputation: 107247

You'll need to change the method signature like so:

private T Deserialize<T>(string xmlContent)

Then, you'll explicitly need to provide the type parameter every time you call the method, because T cannot be inferred (e.g. from the parameters), i.e.

var widget = Deserialize<Widget>(someXmlString);

Edit As per @pswg's comment, you could also make the whole class generic, if this makes sense to do so. You then wouldn't need to specify the type parameter in on the Deserialize method, as it is now inherent in the class. You will however need to make the method more visible (e.g. public) if it is to be called outside of the class.

var widgetDeserializer = new MyDeserializerClass<Widget>();
var widget = widgetDeserializer.Deserialize(someXmlString);

Upvotes: 4

phil
phil

Reputation: 959

You need to specify the Type of the deserialized object...

private T Deserialize<T>(string xmlContent)
{
    ....
}

Upvotes: 2

A.T.
A.T.

Reputation: 26312

it should be something like this

private T FuncName<T>(T param) where T : class
{
            return param;
}

Upvotes: 0

Related Questions