src/Cassandra/Utils.cs
/// <summary>
/// Returns true if the type is IDictionary{T} or implements IDictionary{T}
/// </summary>
Returns true if the type is IDictionary{T} or implements IDictionary{T}
Returns true if the type is IDictionary { T } or implements IDictionary { T }
public static bool IsIDictionary(Type t, out Type keyType, out Type valueType)
        {
            var typeInfo = t.GetTypeInfo();
            var isIDictionary = typeInfo.IsGenericType && 
                typeInfo.GetGenericTypeDefinition() == typeof(IDictionary<,>);
            Type[] subTypes;
            if (isIDictionary)
            {
                subTypes = typeInfo.GetGenericArguments();
                keyType = subTypes[0];
                valueType = subTypes[1];
                return true;
            }
            var implementedIDictionary = typeInfo
                .GetInterfaces()
                .FirstOrDefault(
                    i => i.GetTypeInfo().IsGenericType &&
                    i.GetTypeInfo().GetGenericTypeDefinition() == typeof(IDictionary<,>));
            if (implementedIDictionary == null)
            {
                keyType = null;
                valueType = null;
                return false;
            }
            subTypes = implementedIDictionary.GetTypeInfo().GetGenericArguments();
            keyType = subTypes[0];
            valueType = subTypes[1];
            return true;
        }
public static bool IsIDictionary ( Type t , out Type keyType , out Type valueType ) { var typeInfo = t . GetTypeInfo ( ) ; var isIDictionary = typeInfo . IsGenericType && typeInfo . GetGenericTypeDefinition ( ) == typeof ( IDictionary < , > ) ; Type [ ] subTypes ; if ( isIDictionary ) { subTypes = typeInfo . GetGenericArguments ( ) ; keyType = subTypes [ 0 ] ; valueType = subTypes [ 1 ] ; return true ; } var implementedIDictionary = typeInfo . GetInterfaces ( ) . FirstOrDefault ( i => i . GetTypeInfo ( ) . IsGenericType && i . GetTypeInfo ( ) . GetGenericTypeDefinition ( ) == typeof ( IDictionary < , > ) ) ; if ( implementedIDictionary == null ) { keyType = null ; valueType = null ; return false ; } subTypes = implementedIDictionary . GetTypeInfo ( ) . GetGenericArguments ( ) ; keyType = subTypes [ 0 ] ; valueType = subTypes [ 1 ] ; return true ; }
Returns true if the type is IDictionary{T} or implements IDictionary{T}
Returns true if the type is IDictionary { T } or implements IDictionary { T }
t
Type
Type
out