CSharp examples for System.Reflection:Interface
Get Read Only List Interface
using System.Threading.Tasks; using System.Text; using System.Runtime.Serialization; using System.Runtime.CompilerServices; using System.Reflection.Emit; using System.Reflection; using System.Linq; using System.IO;// w ww.ja v a 2 s. c om using System.Globalization; using System.Collections.Generic; using System; public class Main{ public static Type GetReadOnlyListInterface(this Type t) { return t.GetContainerInterface(typeof(IReadOnlyList<>)); } public static Type GetContainerInterface(this Type t, Type containerType) { return (t.IsGenericType() && t.GetGenericTypeDefinition() == containerType) ? t : t.GetInterfaces().First(i => i.IsGenericType() && i.GetGenericTypeDefinition() == containerType); } }