新文章 网摘 文章 随笔 日记

判断某个实例是否是某个泛型接口的实现

        public virtual bool IsInstanceOfInterface(object message)
        {
            bool result = message.GetType().GetInterfaces().Any(x =>
                x.IsGenericType &&
                x.GetGenericTypeDefinition() == typeof(IMessage<>));
            return result;
        }

https://stackoverflow.com/questions/503263/how-to-determine-if-a-type-implements-a-specific-generic-interface-type

posted @ 2020-10-28 15:59  岭南春  阅读(170)  评论(0)    收藏  举报