Пример #1
0
        private void WriteConversion(Type type, int propOffset)
        {
            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                WriteConversion(type.GetGenericArguments()[0], propOffset);
                return;
            }

            if (_converter.IsPrimitiveType(type))
            {
                if (type == typeof(string))
                {
                    WritePropAccess(propOffset);
                    return;
                }

                string sqlTypeName;

                if (!ClrToSqlMapping.TryGetValue(type, out sqlTypeName))
                {
                    throw new NotSupportedException(string.Format("Type {0} is not supported", type.FullName));
                }

                WriteConversionExpression(sqlTypeName, propOffset, type == typeof(DateTime) ? 127: 0);
            }
            else
            {
                WritePropAccess(propOffset);
            }
        }
Пример #2
0
        private MtTypeDefinition BuildMtType(ISqlConnectionProvider connectionProvider, Type clrType, IMtTypeStorageProvider typeStorageProvider, bool forceComplexType)
        {
            if (_typeConverter.IsPrimitiveType(clrType))
            {
                return(MtTypeDefinition.MakePrimitive(Guid.NewGuid(), clrType));
            }

            // forceComplexType is the hack that prevents MT type system from traversing types of complex properties.
            // Instead we mark such properties as 'complex' at later will store them as JSON
            if (forceComplexType)
            {
                return(MtTypeDefinition.MakeComplexType(Guid.NewGuid(), clrType));
            }

            var mtType = MtTypeDefinition.MakeType(Guid.NewGuid(), clrType);
            int propId = 0;

            foreach (var prop in clrType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                // prevent type parsing for properties: set forceComplexType = true
                var propType = ResolveMtType(connectionProvider, prop.PropertyType, typeStorageProvider, true, true);
                mtType.Properties.Add(new MtPropertyInfo(propId++, prop.Name, mtType, propType));
            }

            return(mtType);
        }