c# - Compare without generics -


There is a little problem to solve me.

I have a list of items, though later the list. Two of the examples will be filled in different types

The first type is MyFirstType & LT; T1, T2 & gt; and the other is MySecondType & LT; T & gt;

Now I need to run the list of objects and ask which of these items is there then I need to make some custom arguments on the item

example for:.

  foreach (object obj in the list) {if (obj MyFirstType & lt; T1, T2 & gt;) {// do something} and if (obj is MySecondType & lt; ... {}} {}}   

The problem can be T or T1 and T2 in any way, so how can I write such a thing - what is a keyword statement that only types the waiver of the forgiveness , But the generic is not inside? If (obj MyFirstType & lt; T1, T2 & gt;) does not work, because it needs solid type for T1 and T2

Just refer to T1 And need to compare without T2 .. How to solve any idea

You can use the property of IsGenericType If you can type type , then check obj.GetType () is normal and GetGenericTypeDefinition is the general type definition, which is To be used to get the typeof (MyFirstType & LT ;, & gt;) and typeof (MySecondType :

  foreach (list obj) {if (obj .GetType () IsGenericType} {if (obj.GetType () GetGenericTypeDefinition () == typeof .. (MyFirstType & lt;; & gt;)) {// do something} else if (obj.GetGenericTypeDefinition () == typeof (MySecondType & lt; & gt;)) {}}}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -