Is Read Only Dictionary Type - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Is Read Only 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;/*  ww w . jav a2s  .c  o m*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        public static bool IsReadOnlyDictionaryType(this Type t)
        {
            return t.IsContainerType(typeof(IReadOnlyDictionary<,>));
        }
        public static bool IsContainerType(this Type t, Type containerType)
        {
            try
            {
                return
                    (t.IsGenericType() && t.GetGenericTypeDefinition() == containerType) ||
                    t.GetInterfaces().Any(i => i.IsGenericType() && i.GetGenericTypeDefinition() == containerType);
            }
            catch (Exception) { return false; }
        }
}

Related Tutorials