Is there a good way to use a object from Type Type in a generic method?
Type type = typeof(object); GenericMethod</*use Type here*/>();
Type type = typeof(object); GenericMethod</*use Type here*/>();
I have a lot of serialized different Objects in a Database along with their typename as string. All of them share the same Interface. Now i want to deserialize all of those to the right Objects. Therefore i created a Application scanner that collects the Types for all those objects. Now i want to compare the typenames and deserialize them in a loop. All of this feels wrong.
private IInterface GetObject(StoredObject storedObject) { foreach(var type in TypeList) { if(type.Name == storedObject.Type) return JsonConvert.DeserializeObject</*TheCorrectType*/>(storedObject.ActualObjectData); } }
private IInterface GetObject(StoredObject storedObject) { foreach(var type in TypeList) { if(type.Name == storedObject.Type) return JsonConvert.DeserializeObject</*TheCorrectType*/>(storedObject.ActualObjectData); } }