C# 检查我的对象是否在C中实现了泛型接口#

C# 检查我的对象是否在C中实现了泛型接口#,c#,C#,我有这样的界面: public interface IEntityWithTypedId<T>{} 公共接口IEntityWithTypedId{} 两个班都有: public abstract class EntityWithTypedId<TId> : IEntityWithTypedId<TId>{...} public abstract class Entity : EntityWithTypedId<int>{...} 公共

我有这样的界面:

public interface IEntityWithTypedId<T>{}
公共接口IEntityWithTypedId{}
两个班都有:

public abstract class EntityWithTypedId<TId> : IEntityWithTypedId<TId>{...}
public abstract class Entity : EntityWithTypedId<int>{...}    
公共抽象类EntityWithTypedId:EntityWithTypedId{…}
公共抽象类实体:EntityWithTypedId{…}
所以我有这样的实体:

public class TestA : Entity
public class TestB : EntityWithTypedId<string>
public class TestC : EntityWithTypedId<byte>
公共类测试:实体
公共类TestB:EntityWithTypedId
公共类TestC:EntityWithTypedId
如何检查我的实体是否实现了IEntityWithTypedId

谢谢

typeof(TestA).GetInterfaces()
.Any(i=>i.GetGenericTypeDefinition()==typeof(IEntityWithTypedId))

在回答之前,我想充分了解一下情况:您如何检查它是否为泛型接口?不,开放泛型类型的可能重复仅在少数地方允许,并且is运算符不是其中之一
typeof(TestA).GetInterfaces()
    .Any(i => i.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>))