Good day to all. Maybe someone has already come across this and can help?
public static class JSON { public static string Serialize_object_TO_JSON<T>(this T Entity) where T:ENT { return JsonConvert.SerializeObject(Entity); } } There is a certain class which inherits ENT and it is possible to transfer it to attributes. Then I had to redo the method so that it worked with the collections:
public static class JSON { public static string Serialize_object_TO_JSON<T>(this T Entity) where T:List<ENT> { return JsonConvert.SerializeObject(Entity); } } After that, the compiler says that it failed to cast the class type that inherits from ENT to the type List<ENT> .
PS Initially, I cannot set a generalization of a finite class, since There are quite a lot of them, that's why I tried to do it through inheritance.
JsonConvert.SerializeObjectmethod and get a JSON object, then whyJsonConvert.SerializeObjectyou need toJsonConvert.SerializeObjectyour own serialization method for a separate object collection? This is not a duplication? - Adampublic static string Serialize_object_TO_JSON<T>(this List<T> Entity) where T:ENT- Grundy