简体   繁体   中英

Is there any way to pass an undefined object as parameter? c#

I have a method that works with a defined data object type, like this:

public static ItemEdificio JSONtoOBJECT(this string JSONstring)
{
   return new JavaScriptSerializer().Deserialize<ItemEdificio>(JSONstring);
}

Is there any way to convert the "ItemEdificio" into something than actualy vary according to the object type?

Keep in mind that this is made using the Newtonsoft library.

public static T JSONtoOBJECT<T>(this string JSONstring)
{
    return new JavaScriptSerializer().Deserialize<T>(JSONstring);
}

Thats what generics ( https://msdn.microsoft.com/en-us/library/0x6a29h6.aspx ) are for.

You call it like this: MyType instance = jsonData.JSONtoOBJECT<MyType>();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM