Is Exactly Dictionary Type - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Is Exactly Dictionary Type

Demo Code


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 w w  .j  a v  a  2  s  .c  om*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        public static bool IsExactlyDictionaryType(this Type t)
        {
            if (!t.IsGenericType()) return false;

            var generic = t.GetGenericTypeDefinition();

            return generic == typeof(Dictionary<,>);
        }
        public static bool IsGenericType(this Type type)
        {
            var info = type.GetTypeInfo();

            return info.IsGenericType;
        }
}

Related Tutorials