Question

This is what is happening. I have a method called "Load" that takes a Hashtable of various parameters and returns an object serialized on disk.

public static T Load<T>(Hashtable settings){}

When calling load the user passes the settings hashtable and the type of data they want. This is how I am trying to call it:

var data =DGSave.DGSave.Load<Type.GetType(type.ToString())>(h);

But it keeps throwing this error:

Error CS0019: Operator '<' cannot be applied to operands of type 'method group' and 'System.Type' (CS0019)

My question is how can I pass the type of data I am retrieving using a variable (in this example it is "type").

Sorry if my explanation was not clear, I suck at explaining things.

Was it helpful?

Solution

You can handle id with reflection

var type = typeof(DGSave.DGSave);
var method = type.GetMethod("Load", BindingFlags.Static).MakeGenericMethod(typeof(string));
method.Invoke(null, new object[] {h});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top