[英]Checking if my object implements a generic interface in C#
我有那个界面:
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<>))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.