I have a function
public static async void MyFunction(object Obj)
{
if (Obj.GetType() == typeof(Dictionary<string, string>))
{
// My Code
}
}
I want to check if parameter Obj is of type Dictionary<string, string> or Dictionary<string, string>.Union(Dictionary<string, string>).
What || condition should I put in the above if statement so that it will execute if block if the object passed to the function is of type Dictioary or Union of Dictionaries?
How do I do it?
Using an extension method:
You can test:
This does not guarantee
Objis the product of a call toUnion. If you need to do that, you need to delve into the type.Using some extension methods to make Reflection easier:
You can determine that the object is from a
UnionofDictionary. Note that this depends on internals of .Net Core and may not work in the future: