Object - IsClass
A T extension method that query if '@this' is class.
public static void Main() { string str = ""; string[] strArray = {"a", "b", "c"}; List<int> list = new List<int>(); IEnumerable<Char> charList = new List<char> (){ 'a', 'b' }; object[] objList = { str, strArray, 2.3, list, charList, 2 }; foreach (var t in objList) { //C# Extension Method: Object - IsClass Console.WriteLine("{0,-15} IsClass = {1}", t.GetType(), t.IsClass()); } }
View Source
public static partial class Extensions { /// <summary> /// A T extension method that query if '@this' is class. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="this">The @this to act on.</param> /// <returns>true if class, false if not.</returns> public static bool IsClass<T>(this T @this) { return @this.GetType().IsClass; } }