Beispiel #1
0
        // Token: 0x0600177B RID: 6011 RVA: 0x0006F0E0 File Offset: 0x0006D2E0
        public static void GetDictionaryKeyValueTypes(Type dictionaryType, out Type keyType, out Type valueType)
        {
            Class_517.ArgumentNotNull(dictionaryType, "type");
            Type type;

            if (Class_514.ImplementsGenericDefinition(dictionaryType, typeof(IDictionary <, >), out type))
            {
                if (type.IsGenericTypeDefinition)
                {
                    throw new Exception("Type {0} is not a dictionary.".FormatWith(CultureInfo.InvariantCulture, dictionaryType));
                }
                Type[] genericArguments = type.GetGenericArguments();
                keyType   = genericArguments[0];
                valueType = genericArguments[1];
                return;
            }
            else
            {
                if (typeof(IDictionary).IsAssignableFrom(dictionaryType))
                {
                    keyType   = null;
                    valueType = null;
                    return;
                }
                throw new Exception("Type {0} is not a dictionary.".FormatWith(CultureInfo.InvariantCulture, dictionaryType));
            }
        }
Beispiel #2
0
        // Token: 0x0600177A RID: 6010 RVA: 0x0006F044 File Offset: 0x0006D244
        public static Type GetCollectionItemType(Type type)
        {
            Class_517.ArgumentNotNull(type, "type");
            if (type.IsArray)
            {
                return(type.GetElementType());
            }
            Type type2;

            if (Class_514.ImplementsGenericDefinition(type, typeof(IEnumerable <>), out type2))
            {
                if (type2.IsGenericTypeDefinition)
                {
                    throw new Exception("Type {0} is not a collection.".FormatWith(CultureInfo.InvariantCulture, type));
                }
                return(type2.GetGenericArguments()[0]);
            }
            else
            {
                if (typeof(IEnumerable).IsAssignableFrom(type))
                {
                    return(null);
                }
                throw new Exception("Type {0} is not a collection.".FormatWith(CultureInfo.InvariantCulture, type));
            }
        }
Beispiel #3
0
        // Token: 0x06001775 RID: 6005 RVA: 0x0006EE98 File Offset: 0x0006D098
        public static bool ImplementsGenericDefinition(Type type, Type genericInterfaceDefinition)
        {
            Type type2;

            return(Class_514.ImplementsGenericDefinition(type, genericInterfaceDefinition, out type2));
        }
Beispiel #4
0
 // Token: 0x06001749 RID: 5961 RVA: 0x0006E264 File Offset: 0x0006C464
 public static bool IsDictionaryType(Type type)
 {
     Class_517.ArgumentNotNull(type, "type");
     return(typeof(IDictionary).IsAssignableFrom(type) || Class_514.ImplementsGenericDefinition(type, typeof(IDictionary <, >)));
 }