我有那个界面:
public interface IEntityWithTypedId<T>{}
并且有两个类:
public abstract class EntityWithTypedId<TId> : IEntityWithTypedId<TId>{...}
public abstract class Entity : EntityWithTypedId<int>{...}
所以我有这样的实体:
public class TestA : Entity
public class TestB : EntityWithTypedId<string>
public class TestC : EntityWithTypedId<byte>
如何检查我的实体是否实现了 IEntityWithTypedId ?
谢谢
最佳答案
typeof(TestA).GetInterfaces()
.Any(i => i.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>))
关于c# - 检查我的对象是否在 C# 中实现通用接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22963018/