/// <summary> /// Add the given NpgsqlNativeTypeInfo to this mapping. /// </summary> public void AddType(NpgsqlNativeTypeInfo T) { if (NameIndex.ContainsKey(T.Name)) { throw new Exception("Type already mapped"); } NameIndex[T.Name] = T; NpgsqlDbTypeIndex[T.NpgsqlDbType] = T; DbTypeIndex[T.DbType] = T; if (!T.IsArray) { NpgsqlNativeTypeInfo arrayType = NpgsqlNativeTypeInfo.ArrayOf(T); NameIndex[arrayType.Name] = arrayType; NameIndex[arrayType.CastName] = arrayType; NpgsqlDbTypeIndex[arrayType.NpgsqlDbType] = arrayType; } }
/// <summary> /// Find a NpgsqlNativeTypeInfo in the default types map that can handle objects /// of the given System.Type. /// </summary> public static bool TryGetNativeTypeInfo(Type type, out NpgsqlNativeTypeInfo typeInfo) { if (NativeTypeMapping.TryGetValue(type, out typeInfo)) { return(true); } // At this point there is no direct mapping, so we see if we have an array or IEnumerable<T>. // Note that we checked for a direct mapping first, so if there is a direct mapping of a class // which implements IEnumerable<T> we will use that (currently this is only string, which // implements IEnumerable<char>. Type elementType = null; NpgsqlNativeTypeInfo elementTypeInfo = null; if (TestTypedEnumerator(type, out elementType) && TryGetNativeTypeInfo(elementType, out elementTypeInfo)) { typeInfo = NpgsqlNativeTypeInfo.ArrayOf(elementTypeInfo); return(true); } return(false); }