Currently im facing the problem I need to create an instance of Dictionary with any type of its cases. The types are delivered by the arguments of the method. I do not simply want to create a dynamic or object type Dictionary, because this faces the user alot of convertion problems by using my library. I also cannot use a simple constructor, because my method fills the Dictionary with data (that is stored in a file) in real. It's important to create the specific dictionary by Type variables. This is what im thinking of:
public static Dictionary<dynamic, dynamic> createDict(Type type1, Type type2)
{
// how to create the dictionary?
// im filling my dictionary with any data ...
return dict;
}
Here the user calls my method:
Dictionary<string, int> dict = MyLib.createDict(typeof(string), typeof(int));
// or
MyOwnType myInstance = new MyOwnType();
Dictionary<string, MyOwnType> dict = MyLib.createDict(typeof(string), myInstance.GetType());