find Interface

  • Thread starter Thread starter Andrzej Kaczmarczyk
  • Start date Start date
A

Andrzej Kaczmarczyk

Hi

How to find out in templated class if a type is implementing an interface.
In particular I want to find out whether the type passed is a INullableValue

I came up with somethig like this:
class myClass<PropertyT>
{
public DoSomething() {
if ( typeof(PropertyT).GetInterface(typeof(INullableValue).ToString())
!= null ) {
// PropertyT is INullable
}
}
}

is there a simpler way?

CUIN Kaczy
 
Hi,

If you have an instance of PropertyT you can do this:

PropertyT instance;

INullableValue var = instance as INullableValue
if ( var != null )
// PropertyT is INullable


If all you have to work are the types (not any instance) then I thikn that
your way is the way to go


cheers,
 
Back
Top