public override NpgsqlArrayTypeMapping FlipArrayListClrType(Type newType)
    {
        var elementType = ClrType.GetGenericArguments()[0];

        if (newType.IsGenericList())
        {
            var newTypeElement = newType.GetGenericArguments()[0];

            return(newTypeElement == elementType
                ? this
                : throw new ArgumentException(
                       $"Mismatch in list element CLR types when converting a type mapping: {newTypeElement.Name} and {elementType.Name}"));
        }

        if (newType.IsArray)
        {
            var arrayElementType = newType.GetElementType() !;

            return(arrayElementType == elementType
                ? new NpgsqlArrayArrayTypeMapping(newType, ElementMapping)
                : throw new ArgumentException(
                       "Mismatch in list element CLR types when converting a type mapping: " +
                       $"{arrayElementType} and {elementType.Name}"));
        }

        throw new ArgumentException($"Non-array/list type: {newType.Name}");
    }
Exemplo n.º 2
0
        /// <summary>
        /// Prints the data convert method.
        /// </summary>
        /// <param name="methodPrefix">The method prefix.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public string PrintDataConvertMethod(string methodPrefix, EntityMap entity)
        {
            string tstring;

            if (IsComplexType && (entity.Parent != null))
            {
                var complexT = entity.Parent.ComplexTypes[ComplexTypeName];
                if ((complexT != null) && complexT.IsEnum)
                {
                    return(string.Format("ReadEnum<{0}>", complexT.FullName));
                }
            }

            if (ClrType.IsGenericType && ClrType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                var args = ClrType.GetGenericArguments();
                tstring       = ToPrintString(args[0], false);
                methodPrefix += "Nullable";
            }
            else
            {
                tstring = ToPrintString(ClrType);
            }
            return(string.Format("{0}{1}", methodPrefix, Goliath.Data.Utils.Inflector.Pascalize(tstring)));
        }
Exemplo n.º 3
0
            internal override IEnumerable <Type> GetChildTypes()
            {
                // Collect information...
                Debug.Assert(
                    ClrType.IsGenericType() &&
                    typeof(IGrouping <,>).Equals(ClrType.GetGenericTypeDefinition()));
                var keyType          = ClrType.GetGenericArguments()[0];
                var groupElementType = ClrType.GetGenericArguments()[1];

                // key
                yield return(keyType);

                // group
                yield return(typeof(IEnumerable <>).MakeGenericType(groupElementType));
            }
Exemplo n.º 4
0
            internal override Expression Emit(List <TranslatorResult> propertyTranslatorResults)
            {
                // Create expression of the form:
                // new Grouping<K, T>(children[0], children[1])

                // Collect information...
                Debug.Assert(
                    ClrType.IsGenericType() &&
                    typeof(IGrouping <,>).Equals(ClrType.GetGenericTypeDefinition()));
                Debug.Assert(propertyTranslatorResults.Count == 2);
                var keyType          = ClrType.GetGenericArguments()[0];
                var groupElementType = ClrType.GetGenericArguments()[1];
                var groupType        = typeof(Grouping <,>).MakeGenericType(keyType, groupElementType);
                var constructor      = groupType.GetConstructors().Single();

                // new Grouping<K, T>(children[0], children[1])
                Expression newGrouping = Expression.Convert(
                    Expression.New(constructor, GetPropertyReaders(propertyTranslatorResults)), ClrType);

                return(newGrouping);
            }