3

I have that interface :

public interface IEntityWithTypedId<T>{}

And have both classes :

public abstract class EntityWithTypedId<TId> : IEntityWithTypedId<TId>{...}
public abstract class Entity : EntityWithTypedId<int>{...}    

So I have entities like those:

public class TestA : Entity
public class TestB : EntityWithTypedId<string>
public class TestC : EntityWithTypedId<byte>

How can I check if my entities implements IEntityWithTypedId ?

Thanks

Paul
  • 12,359
  • 20
  • 64
  • 101
  • Before I answer, I'd like to fully understand the situation: How would you check if it weren't a generic interface? – O. R. Mapper Apr 09 '14 at 12:48
  • possible duplicate of [How to determine if a type implements a specific generic interface type](http://stackoverflow.com/questions/503263/how-to-determine-if-a-type-implements-a-specific-generic-interface-type) – magnattic Apr 09 '14 at 18:42

1 Answers1

5
typeof(TestA).GetInterfaces()
    .Any(i => i.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>))
Julien Roncaglia
  • 17,397
  • 4
  • 57
  • 75