Exemplo n.º 1
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.º 2
0
        protected internal virtual TypeConverter GetTypeConverter()
        {
            var tca = ClrType.GetCustomAttributes(typeof(TypeConverterAttribute), false).Cast <TypeConverterAttribute>().FirstOrDefault();

            if (tca != null)
            {
                return(Activator.CreateInstance(Type.GetType(tca.ConverterTypeName)) as TypeConverter);
            }
            if (ClrType.IsEnum
#if NETFX_CORE
                    ()
#endif
                )
            {
                return(new DelegateTypeConverter <object>((context, culture, val) => Enum.Parse(ClrType, val, false)));
            }
            if (ClrType.IsGenericType
#if NETFX_CORE
                    ()
#endif
                && ClrType.GetGenericTypeDefinition().Equals(typeof(Nullable <>)))
            {
                var nullableKind      = Nullable.GetUnderlyingType(ClrType);
                var nullableType      = ClrType;
                var baseTypeConverter = XamlType.GetXamlType(nullableKind).TypeConverter;
                return(new DelegateTypeConverter <object>((context, culture, val) =>
                {
                    var result = baseTypeConverter.ConvertFrom(context, culture, val);
                    return Activator.CreateInstance(nullableType, result);
                }));
            }
            return(null);
        }
Exemplo n.º 3
0
            internal override IEnumerable <Type> GetChildTypes()
            {
                // Collect information...
                Debug.Assert(ClrType.IsGenericType &&
                             typeof(IGrouping <,>).Equals(ClrType.GetGenericTypeDefinition()));
                Type keyType          = this.ClrType.GetGenericArguments()[0];
                Type groupElementType = this.ClrType.GetGenericArguments()[1];

                // key
                yield return(keyType);

                // group
                yield return(typeof(IEnumerable <>).MakeGenericType(groupElementType));
            }
Exemplo n.º 4
0
            internal override Expression Emit(Translator translator, 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);
                Type            keyType          = this.ClrType.GetGenericArguments()[0];
                Type            groupElementType = this.ClrType.GetGenericArguments()[1];
                Type            groupType        = typeof(Grouping <,>).MakeGenericType(keyType, groupElementType);
                ConstructorInfo constructor      = groupType.GetConstructors().Single();

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

                return(newGrouping);
            }