コード例 #1
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Map <SqliteLanguage>().To <CsharpLanguage>()
            .From(SqliteType.Real).To("double").FromSystem()
            .From(SqliteType.Numeric).To("double").FromSystem()
            .From(SqliteType.Integer).To("int").FromSystem()
            .From(SqliteType.Text).To("string").Nullable().FromSystem()
            .From(SqliteType.Blob).To("byte[]").Nullable().FromSystem();

            typeMapping.Map <ReflectionLanguage>().To <SqliteLanguage>()
            .From("System.Boolean").To(SqliteType.Integer)
            .From("System.Byte").To(SqliteType.Integer)
            .From("System.Char").To(SqliteType.Integer)
            .From("System.DateTime").To(SqliteType.Text)
            .From("System.Decimal").To(SqliteType.Integer)
            .From("System.Double").To(SqliteType.Integer)
            .From("System.Guid").To(SqliteType.Text)
            .From("System.Int16").To(SqliteType.Integer)
            .From("System.Int32").To(SqliteType.Integer)
            .From("System.Int64").To(SqliteType.Integer)
            .From("System.Single").To(SqliteType.Integer)
            .From("System.String").To(SqliteType.Text)
            .From("System.TimeSpan").To(SqliteType.Text)
            .From("System.UInt16").To(SqliteType.Integer)
            .From("System.UInt32").To(SqliteType.Integer)
            .From("System.UInt64").To(SqliteType.Integer);

            return(typeMapping);
        }
コード例 #2
0
 public void SetTypeMapping(ITypeMapping typeMapping)
 {
     this.typeMappings.AddOrUpdate(
         string.Concat(typeMapping.FromType.FullName, typeMapping.ToType.FullName),
         typeMapping,
         (key, oldValue) => typeMapping);
 }
コード例 #3
0
        /// <summary>
        /// Applied the <paramref name="mapping"/> from the <paramref name="originalType"/> to a potentially new
        /// <see cref="Type"/>.
        /// </summary>
        /// <param name="originalType">The original <see cref="Type"/>.</param>
        /// <param name="mapping">The type mapping.</param>
        /// <returns>A new <see cref="Type"/> is a mapping has been made; otherwise the
        /// <paramref name="originalType"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="originalType"/> or <paramref name="mapping"/>
        /// parameters are <see langword="null"/>.</exception>
        private static Type ApplyMapping(this Type originalType, ITypeMapping mapping)
        {
            if (originalType == null)
            {
                throw new ArgumentNullException(nameof(originalType));
            }
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            Type newType = mapping.MapTo(originalType);

            if (originalType != newType)
            {
                ////TODO: Look into Tracing.
                ////Trace.TraceInformation(
                ////    "The type '{0}' was mapped to the type '{1}' by the mapping '{2}'.",
                ////    originalType,
                ////    newType,
                ////    mapping.Name);
            }

            return(newType);
        }
コード例 #4
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Map <ReflectionLanguage>().To <CsharpLanguage>()
            .From("System.Array").To("Array").Namespace("System").FromSystem()
            .From("System.Boolean").To("bool").FromSystem()
            .From("System.Byte").To("byte").FromSystem()
            .From("System.Char").To("char").FromSystem()
            .From("System.DateTime").To("DateTime").Namespace("System").FromSystem()
            .From("System.Decimal").To("decimal").FromSystem()
            .From("System.Double").To("double").FromSystem()
            .From("System.Guid").To("Guid").Namespace("System").FromSystem()
            .From("System.Int16").To("short").FromSystem()
            .From("System.Int32").To("int").FromSystem()
            .From("System.Int64").To("long").FromSystem()
            .From("System.Object").To("object").FromSystem()
            .From("System.Single").To("float").FromSystem()
            .From("System.String").To("string").Nullable().FromSystem()
            .From("System.TimeSpan").To("TimeSpan").Namespace("System").FromSystem()
            .From("System.UInt16").To("ushort").FromSystem()
            .From("System.UInt32").To("uint").FromSystem()
            .From("System.UInt64").To("ulong").FromSystem()
            .From("System.Void").To("void").FromSystem()
            .From("System.Collections.Generic.ICollection").To("ICollection").Namespace("System.Collections.Generic").FromSystem()
            .From("System.Collections.Generic.IList").To("IList").Namespace("System.Collections.Generic").FromSystem()
            .From("System.Collections.Generic.List").To("List").Namespace("System.Collections.Generic").FromSystem()
            .From("System.Collections.Generic.IEnumerable").To("IEnumerable").Namespace("System.Collections.Generic").FromSystem()
            .From("System.Collections.Generic.Dictionary").To("Dictionary").Namespace("System.Collections.Generic").FromSystem()
            .From("System.Collections.Generic.IDictionary").To("IDictionary").Namespace("System.Collections.Generic").FromSystem()
            .From("System.Nullable").To("Nullable").Nullable().FromSystem();

            typeMapping.Map <ReflectionLanguage>().To <TypeScriptLanguage>()
            .From("System.Array").To("Array").Nullable().FromSystem().Default(Code.Instance.TypeScript("[]"))
            .From("System.Boolean").To("boolean").Nullable().FromSystem().Default(Code.Instance.Boolean(false))
            .From("System.Byte").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.Char").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.DateTime").To("Date").Nullable().FromSystem().Default(Code.Instance.New(Code.Instance.Type("Date"), Code.Instance.Number(0)))
            .From("System.Decimal").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.Double").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.Guid").To("string").Nullable().FromSystem()
            .From("System.Int16").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.Int32").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.Int64").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.Object").To("unknown").Nullable().FromSystem()
            .From("System.Single").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.String").To("string").Nullable().FromSystem()
            .From("System.TimeSpan").To("string").Nullable().FromSystem()
            .From("System.UInt16").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.UInt32").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.UInt64").To("number").Nullable().FromSystem().Default(Code.Instance.Number(0))
            .From("System.Void").To("void").Nullable().FromSystem()
            .From("System.Collections.Generic.ICollection").To("Array").Nullable().FromSystem().Default(Code.Instance.TypeScript("[]"))
            .From("System.Collections.Generic.IList").To("Array").Nullable().FromSystem().Default(Code.Instance.TypeScript("[]"))
            .From("System.Collections.Generic.List").To("Array").Nullable().FromSystem().Default(Code.Instance.TypeScript("[]"))
            .From("System.Collections.Generic.IEnumerable").To("Array").Nullable().FromSystem().Default(Code.Instance.TypeScript("[]"))
            .From("System.Collections.Generic.Dictionary").To("Dictionary").Nullable().FromSystem().Default(Code.Instance.TypeScript("{}"))
            .From("System.Collections.Generic.IDictionary").To("Dictionary").Nullable().FromSystem().Default(Code.Instance.TypeScript("{}"))
            .From("System.Nullable").To("Nullable").Nullable().FromSystem();

            return(typeMapping);
        }
コード例 #5
0
        private Expression MakeColumnExpression(AliasedTableExpression table, IProperty property)
        {
            ITypeMapping typeMapping = default;

            var sourceMapping = relationalTypeMappingSource.FindMapping(property);

            if (!(sourceMapping is null))
            {
                typeMapping
                    = new AdHocTypeMapping(
                          sourceMapping.ClrType,
                          sourceMapping.Converter?.ProviderClrType ?? sourceMapping.ClrType,
                          sourceMapping.DbType,
                          sourceMapping.StoreType,
                          sourceMapping.Converter?.ConvertFromProviderExpression,
                          sourceMapping.Converter?.ConvertToProviderExpression);
            }

            var nullable = GetColumnNullability(property);

            return(new SqlColumnExpression(
                       table,
                       property.Relational().ColumnName,
                       property.ClrType,
                       nullable,
                       typeMapping));
        }
コード例 #6
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Map <JsonLanguage>().To <CsharpLanguage>()
            .From(JTokenType.Array.ToString()).To("List").Nullable().Namespace("System.Collections.Generic").FromSystem()
            .From(JTokenType.Boolean.ToString()).To("bool").FromSystem()
            .From(JTokenType.Bytes.ToString()).To("byte").FromSystem()
            .From(JTokenType.Integer.ToString()).To("int").FromSystem()
            .From(JTokenType.Float.ToString()).To("double").FromSystem()
            .From(JTokenType.String.ToString()).To("string").Nullable().FromSystem()
            .From(JTokenType.Date.ToString()).To("DateTime").Namespace("System").FromSystem()
            .From(JTokenType.Guid.ToString()).To("Guid").Namespace("System").FromSystem()
            .From(JTokenType.Uri.ToString()).To("Uri").Namespace("System").FromSystem()
            .From(JTokenType.TimeSpan.ToString()).To("TimeSpan").Namespace("System").FromSystem()
            .From(JTokenType.Object.ToString()).To("object").Nullable().FromSystem();

            typeMapping.Map <JsonLanguage>().To <TypeScriptLanguage>()
            .From(JTokenType.Array.ToString()).To("Array").Nullable().Namespace("System.Collections.Generic").FromSystem()
            .From(JTokenType.Boolean.ToString()).To("boolean").Nullable().FromSystem()
            .From(JTokenType.Bytes.ToString()).To("number").Nullable().FromSystem()
            .From(JTokenType.Integer.ToString()).To("number").Nullable().FromSystem()
            .From(JTokenType.Float.ToString()).To("number").Nullable().FromSystem()
            .From(JTokenType.String.ToString()).To("string").Nullable().FromSystem()
            .From(JTokenType.Date.ToString()).To("Date").Nullable().FromSystem()
            .From(JTokenType.Guid.ToString()).To("string").Nullable().FromSystem()
            .From(JTokenType.Uri.ToString()).To("string").Nullable().FromSystem()
            .From(JTokenType.TimeSpan.ToString()).To("string").Nullable().FromSystem()
            .From(JTokenType.Object.ToString()).To("Object").Nullable().FromSystem();

            return(typeMapping);
        }
コード例 #7
0
        /// <summary>
        /// Mapping配置实体类型。
        /// </summary>
        /// <param name="type"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        public object Mapping(Type type, XElement element, IConvertCaseStrategy convertCaseStrategy)
        {
            // 获取mappinger选择器
            IMappinger mappinger = MappingerSelector.Get(type, convertCaseStrategy);

            convertCaseStrategy = convertCaseStrategy ?? new DefaultConvertCaseStrategy();

            // 如果不是entity,直接执行返回值
            if (!(mappinger is EntityMappinger))
            {
                mappinger.ConvertCaseStrategy = convertCaseStrategy;
                return(mappinger.Mapping(element, type));
            }


            // 创建实例
            var instance = Activator.CreateInstance(type);

            // 创建 mapping
            ITypeMapping typeMapping = MappingFactory.CreateMapping(type, element, convertCaseStrategy);

            // 执行
            typeMapping.Apply(instance);
            return(instance);
        }
コード例 #8
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Boolean.ToString(), CsharpLanguage.Instance, "bool", fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Bytes.ToString(), CsharpLanguage.Instance, "byte", fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Integer.ToString(), CsharpLanguage.Instance, "int", fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Float.ToString(), CsharpLanguage.Instance, "double", fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.String.ToString(), CsharpLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Date.ToString(), CsharpLanguage.Instance, "DateTime", false, "System", true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Guid.ToString(), CsharpLanguage.Instance, "Guid", false, "System", true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Uri.ToString(), CsharpLanguage.Instance, "Uri", false, "System", true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.TimeSpan.ToString(), CsharpLanguage.Instance, "TimeSpan", false, "System", true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Array.ToString(), CsharpLanguage.Instance, "List", false, "System.Collections.Generic", true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Object.ToString(), CsharpLanguage.Instance, "object");

            typeMapping.Add(JsonLanguage.Instance, JTokenType.Boolean.ToString(), TypeScriptLanguage.Instance, "boolean", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Bytes.ToString(), TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Integer.ToString(), TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Float.ToString(), TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.String.ToString(), TypeScriptLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Date.ToString(), TypeScriptLanguage.Instance, "Date", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Guid.ToString(), TypeScriptLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Uri.ToString(), TypeScriptLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.TimeSpan.ToString(), TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Array.ToString(), TypeScriptLanguage.Instance, "Array", true, fromSystem: true);
            typeMapping.Add(JsonLanguage.Instance, JTokenType.Object.ToString(), TypeScriptLanguage.Instance, "Object", true, fromSystem: true);
            return(typeMapping);
        }
コード例 #9
0
ファイル: Query.cs プロジェクト: charlieknoll/query-first
        public Query(CodeGenerationContext _ctx)
        {
            ctx = _ctx;
            var textDoc = ((TextDocument)ctx.QueryDoc.Object());
            var start   = textDoc.StartPoint;

            text = start.CreateEditPoint().GetText(textDoc.EndPoint);
            map  = ctx.Map;
        }
コード例 #10
0
        public SqlParameterExpression WithMapping(ITypeMapping mapping)
        {
            if (mapping is null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            return(new SqlParameterExpression(Expression, IsNullable, mapping));
        }
コード例 #11
0
 public void Accept(ITypeMapping mapping)
 {
     if (mapping == null)
     {
         return;
     }
     this._visitor.Visit(mapping);
     this.Accept(mapping.Properties);
 }
コード例 #12
0
 public ViewColumn(Column column)
 {
     FBase = column;
     foreach (Database ODatabase in column.DatabaseRelationships)
     {
         FDatabaseRelationships.Add(ODatabase.Name, new ViewDatabase(ODatabase));
     }
     FTypeMapping = Provider.Current.GetTypeMapping(FBase.DataType);
 }
コード例 #13
0
        public TypeMapping ToTypeMapping(ITypeMapping converted)
        {
            var result = new TypeMapping();

            result.DestinationTypeSetName = converted.DestinationTypeSetName;
            result.SourceTypeSetName      = converted.SourceTypeSetName;
            result.TypeMappingItems       = (converted.TypeMappingItems ?? new List <ITypeMappingItem>()).Select(typeMappingItemConverter.ToTypeMappingItem)
                                            .Cast <ITypeMappingItem>().ToList();
            return(result);
        }
コード例 #14
0
        /// <summary>
        /// Adds or returns a mapping between two types
        /// </summary>
        /// <param name="Left">Left type</param>
        /// <param name="Right">Right type</param>
        /// <returns>A mapping object for the two types specified</returns>
        public ITypeMapping Map(Type Left, Type Right)
        {
            var Key = new Tuple <Type, Type>(Left, Right);

            Mappings.AddOrUpdate(Key, x => CreateTypeMapping(x.Item1, x.Item2), (x, y) => y);
            ITypeMapping ReturnValue = null;

            Mappings.TryGetValue(Key, out ReturnValue);
            return(ReturnValue);
        }
コード例 #15
0
        public ElasticQueryParserConfiguration UseMappings <T>(Func <TypeMappingDescriptor <T>, TypeMappingDescriptor <T> > mappingBuilder, Func <ITypeMapping> getMapping) where T : class
        {
            var descriptor = new TypeMappingDescriptor <T>();

            descriptor           = mappingBuilder(descriptor);
            _codeMapping         = descriptor;
            GetServerMappingFunc = getMapping;

            return(this);
        }
コード例 #16
0
        /// <summary>
        /// Adds or returns a mapping between two types
        /// </summary>
        /// <typeparam name="Left">Left type</typeparam>
        /// <typeparam name="Right">Right type</typeparam>
        /// <returns>A mapping object for the two types specified</returns>
        public ITypeMapping <Left, Right> Map <Left, Right>()
        {
            var Key = new Tuple <Type, Type>(typeof(Left), typeof(Right));

            Mappings.AddOrUpdate(Key, x => CreateTypeMapping <Left, Right>(), (x, y) => y);
            ITypeMapping ReturnValue = null;

            Mappings.TryGetValue(Key, out ReturnValue);
            return((ITypeMapping <Left, Right>)ReturnValue);
        }
コード例 #17
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Add(ReflectionLanguage.Instance, "System.Array", CsharpLanguage.Instance, "Array", nameSpace: "System", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Boolean", CsharpLanguage.Instance, "bool", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Byte", CsharpLanguage.Instance, "byte", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Char", CsharpLanguage.Instance, "char", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.DateTime", CsharpLanguage.Instance, "DateTime", nameSpace: "System", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Decimal", CsharpLanguage.Instance, "decimal", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Double", CsharpLanguage.Instance, "double", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Guid", CsharpLanguage.Instance, "Guid", nameSpace: "System", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Int16", CsharpLanguage.Instance, "short", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Int32", CsharpLanguage.Instance, "int", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Int64", CsharpLanguage.Instance, "long", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Object", CsharpLanguage.Instance, "unknown", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Single", CsharpLanguage.Instance, "float", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.String", CsharpLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.TimeSpan", CsharpLanguage.Instance, "TimeSpan", nameSpace: "System", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.UInt16", CsharpLanguage.Instance, "ushort", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.UInt32", CsharpLanguage.Instance, "uint", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.UInt64", CsharpLanguage.Instance, "ulong", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Void", CsharpLanguage.Instance, "void", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Array", CsharpLanguage.Instance, "Array", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.IList", CsharpLanguage.Instance, "IList", nameSpace: "System.Collections.Generic", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.List", CsharpLanguage.Instance, "List", nameSpace: "System.Collections.Generic", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.IEnumerable", CsharpLanguage.Instance, "IEnumerable", nameSpace: "System.Collections.Generic", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.Dictionary", CsharpLanguage.Instance, "Dictionary", nameSpace: "System.Collections.Generic", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Nullable", CsharpLanguage.Instance, "Nullable", nameSpace: "System", fromSystem: true);

            typeMapping.Add(ReflectionLanguage.Instance, "System.Array", TypeScriptLanguage.Instance, "Array", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Boolean", TypeScriptLanguage.Instance, "boolean", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Byte", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Char", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.DateTime", TypeScriptLanguage.Instance, "Date", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Decimal", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Double", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Guid", TypeScriptLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Int16", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Int32", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Int64", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Object", TypeScriptLanguage.Instance, "unknown", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Single", TypeScriptLanguage.Instance, "number", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.String", TypeScriptLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.TimeSpan", TypeScriptLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.UInt16", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.UInt32", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.UInt64", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Void", TypeScriptLanguage.Instance, "void", true, fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Array", TypeScriptLanguage.Instance, "Array", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.IList", TypeScriptLanguage.Instance, "Array", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.List", TypeScriptLanguage.Instance, "Array", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.IEnumerable", TypeScriptLanguage.Instance, "Array", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Collections.Generic.Dictionary", TypeScriptLanguage.Instance, "Dictionary", fromSystem: true);
            typeMapping.Add(ReflectionLanguage.Instance, "System.Nullable", TypeScriptLanguage.Instance, "Nullable", nameSpace: "System", fromSystem: true);
            return(typeMapping);
        }
コード例 #18
0
        public ScalarItem(IOwner owner, Configuration configuration, XElement element)
        {
            FOwner         = owner;
            FConfiguration = configuration;

            if (element.Attribute("type") == null)
            {
                FOwner.Throw(element, "The required attribute 'type' is missing.");
            }

            FType        = element.Attribute("type").Value;
            FTypeMapping = Provider.Current.GetTypeMapping(FType);

            if (element.Attribute("nullable") != null)
            {
                FNullable = element.Attribute("nullable").Value.Equals("true", StringComparison.OrdinalIgnoreCase);
            }

            if (element.Attribute("default") != null)
            {
                FDefault = element.Attribute("default").Value;
            }
            else
            {
                XElement ODefaultElem = element.Element(ItemFile.XmlNamespace + "default");
                if (ODefaultElem != null)
                {
                    FDefault = ODefaultElem.Value;
                }
            }

            if (FDefault != null)
            {
                FNullable = false;
            }

            if (element.Attribute("transform") != null)
            {
                FTransform = element.Attribute("transform").Value;
            }
            else
            {
                XElement OTransformElem = element.Element(ItemFile.XmlNamespace + "transform");
                if (OTransformElem != null)
                {
                    FTransform = OTransformElem.Value;
                }
            }

            foreach (XElement OMethod in element.Elements(ItemFile.XmlNamespace + "method"))
            {
                FMethods.Add(new ScalarMethod(this, FConfiguration, OMethod));
            }
        }
コード例 #19
0
 public SqlColumnExpression(
     AliasedTableExpression table,
     string columnName,
     Type type,
     bool isNullable,
     ITypeMapping typeMapping)
 {
     Table       = table ?? throw new ArgumentNullException(nameof(table));
     ColumnName  = columnName ?? throw new ArgumentNullException(nameof(columnName));
     Type        = type ?? throw new ArgumentNullException(nameof(type));
     IsNullable  = isNullable;
     TypeMapping = typeMapping;
 }
        public string ToContextString(ITypeMapping converted)
        {
            if (converted == null)
            {
                return(string.Empty);
            }
            if (!converted.TypeMappingItems?.Any() ?? false)
            {
                return(string.Empty);
            }
            return(@$ "{StartContext}([->({converted.DestinationTypeSetName})<-]<=>[{ToConstextString(converted.TypeMappingItems)}
]{EndContext}");
        }
コード例 #21
0
        static bool TryAddPropertyFromElement(ITypeMapping typeMapping, ICollection <XElement> elementList, PropertyInfo property, IPropertyStrategy propertyStrategy, string name)
        {
            var element = TakeElement(elementList, name);

            if (element == null)
            {
                return(false);
            }

            var mapper          = propertyStrategy.Mapper ?? MapperSelector.GetFor(property.PropertyType);
            var propertyMapping = new MappingFromElement(element, property, mapper);

            typeMapping.Include(propertyMapping);
            return(true);
        }
コード例 #22
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Add(OpenApiLanguage.Instance, "array", CsharpLanguage.Instance, "List", nameSpace: "System.Collections.Generic", fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "string", CsharpLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "boolean", CsharpLanguage.Instance, "bool", true, fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "integer", CsharpLanguage.Instance, "int", true, fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "number", CsharpLanguage.Instance, "double", true, fromSystem: true);

            typeMapping.Add(OpenApiLanguage.Instance, "array", TypeScriptLanguage.Instance, "Array", fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "string", TypeScriptLanguage.Instance, "string", true, fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "boolean", TypeScriptLanguage.Instance, "boolean", true, fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "integer", TypeScriptLanguage.Instance, "number", true, fromSystem: true);
            typeMapping.Add(OpenApiLanguage.Instance, "number", TypeScriptLanguage.Instance, "number", true, fromSystem: true);

            return(typeMapping);
        }
コード例 #23
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Map <OpenApiLanguage>().To <CsharpLanguage>()
            .From("array").To("List").Namespace("System.Collections.Generic").FromSystem()
            .From("string").To("string").Nullable().FromSystem()
            .From("boolean").To("bool").Nullable().FromSystem()
            .From("integer").To("int").Nullable().FromSystem()
            .From("number").To("double").Nullable().FromSystem();

            typeMapping.Map <OpenApiLanguage>().To <TypeScriptLanguage>()
            .From("array").To("Array").FromSystem()
            .From("string").To("string").Nullable().FromSystem()
            .From("boolean").To("boolean").Nullable().FromSystem()
            .From("integer").To("number").Nullable().FromSystem()
            .From("number").To("number").Nullable().FromSystem();

            return(typeMapping);
        }
コード例 #24
0
        /// <summary>
        /// Applied the <paramref name="mapping"/> from the <paramref name="originalType"/> to a potentially new
        /// <see cref="Type"/>.
        /// </summary>
        /// <param name="originalType">The original <see cref="Type"/>.</param>
        /// <param name="mapping">The type mapping.</param>
        /// <returns>A new <see cref="Type"/> is a mapping has been made; otherwise the
        /// <paramref name="originalType"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="originalType"/> or <paramref name="mapping"/>
        /// parameters are <see langword="null"/>.</exception>
        private static Type ApplyMapping(this Type originalType, ITypeMapping mapping)
        {
            if (originalType == null)
                throw new ArgumentNullException("originalType");
            if (mapping == null)
                throw new ArgumentNullException("mapping");

            Type newType = mapping.MapTo(originalType);
            if (originalType != newType)
            {
                Trace.TraceInformation(
                    "The type '{0}' was mapped to the type '{1}' by the mapping '{2}'.",
                    originalType,
                    newType,
                    mapping.Name);
            }

            return newType;
        }
コード例 #25
0
 public Parameter(IOwner owner, XElement element)
 {
     FOwner = owner;
     if (element.Attribute("name") == null)
     {
         FOwner.Throw(element, "The required attribute 'name' is missing.");
     }
     if (element.Attribute("type") == null)
     {
         FOwner.Throw(element, "The required attribute 'type' is missing.");
     }
     FName         = element.Attribute("name").Value;
     FArgumentName = FName.ToCamelCase();
     FType         = element.Attribute("type").Value;
     FTypeMapping  = Provider.Current.GetTypeMapping(FType);
     if (element.Attribute("nullable") != null)
     {
         FNullable = element.Attribute("nullable").Value.Equals("true", StringComparison.OrdinalIgnoreCase);
     }
 }
コード例 #26
0
        private bool GetServerMapping()
        {
            if (GetServerMappingFunc == null)
            {
                return(false);
            }

            if (_lastMappingUpdate.HasValue && _lastMappingUpdate.Value > DateTime.UtcNow.SubtractMinutes(1))
            {
                return(false);
            }

            try {
                _serverMapping     = GetServerMappingFunc();
                _lastMappingUpdate = DateTime.UtcNow;

                return(true);
            } catch (Exception) {
                return(false);
            }
        }
コード例 #27
0
        // constructor
        public CodeGenerationContext(Document queryDoc)
        {
            tiny          = TinyIoCContainer.Current;
            map           = tiny.Resolve <ITypeMapping>();
            queryHasRun   = false;
            this.queryDoc = queryDoc;
            dte           = queryDoc.DTE;
            query         = new Query(this);


            string currDir = Path.GetDirectoryName(queryDoc.FullName);

            //WriteToOutput("\nprocessing " + queryDoc.FullName );
            // class name and namespace read from user's half of partial class.
            //QfClassName = Regex.Match(query, "(?im)^--QfClassName\\s*=\\s*(\\S+)").Groups[1].Value;
            //QfNamespace = Regex.Match(query, "(?im)^--QfNamespace\\s*=\\s*(\\S+)").Groups[1].Value;
            // doc.fullname started being lowercase ??
            //namespaceAndClassNames = GetNamespaceAndClassNames(resultsClass);

            hlpr = new ADOHelper();
        }
コード例 #28
0
 public static ITypeMapping Initialize(this ITypeMapping typeMapping)
 {
     typeMapping.Map(ODataLanguage.Instance, "Edm.Duration").To(TypeScriptLanguage.Instance, "string", "String");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Binary").To(TypeScriptLanguage.Instance, "string", "String");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Boolean").To(TypeScriptLanguage.Instance, "boolean", "Boolean");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Byte").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Date").To(TypeScriptLanguage.Instance, "Date");
     typeMapping.Map(ODataLanguage.Instance, "Edm.DateTimeOffset").To(TypeScriptLanguage.Instance, "Date");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Decimal").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Double").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Guid").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Int16").To(TypeScriptLanguage.Instance, "string", "String");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Int32").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Int64").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.SByte").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Single").To(TypeScriptLanguage.Instance, "number", "Number");
     typeMapping.Map(ODataLanguage.Instance, "Edm.String").To(TypeScriptLanguage.Instance, "string", "String");
     typeMapping.Map(ODataLanguage.Instance, "Edm.TimeOfDay").To(TypeScriptLanguage.Instance, "string", "String");
     typeMapping.Map(ODataLanguage.Instance, "Edm.Void").To(TypeScriptLanguage.Instance, "void");
     return(typeMapping);
 }
コード例 #29
0
        public static ITypeMapping Initialize(this ITypeMapping typeMapping)
        {
            typeMapping.Map <TsqlLanguage>().To <CsharpLanguage>()
            .From("smallint").To("short").Nullable()
            .From("bigint").To("long").Nullable()
            .From("bit").To("bool").Nullable()
            .From("int").To("int").Nullable()
            .From("date").To("DateTime").Nullable().Namespace("System")
            .From("datetime").To("DateTime").Nullable().Namespace("System")
            .From("datetime2").To("DateTime").Nullable().Namespace("System")
            .From("decimal").To("decimal").Nullable()
            .From("nchar").To("string")
            .From("nvarchar").To("string")
            .From("char").To("string")
            .From("varchar").To("string")
            .From("varbinary").To("byte[]")
            .From("timestamp").To("byte[]")
            .From("uniqueidentifier").To("Guid").Namespace("System")
            .From("float").To("double").Nullable();

            typeMapping.Map <TsqlLanguage>().To <TypeScriptLanguage>()
            .From("smallint").To("number").Nullable()
            .From("bigint").To("number").Nullable()
            .From("bit").To("boolean").Nullable()
            .From("int").To("number").Nullable()
            .From("date").To("Date").Nullable()
            .From("datetime").To("Date").Nullable()
            .From("datetime2").To("Date").Nullable()
            .From("decimal").To("number").Nullable()
            .From("nchar").To("string").Nullable()
            .From("nvarchar").To("string").Nullable()
            .From("char").To("string").Nullable()
            .From("varchar").To("string").Nullable()
            .From("varbinary").To("number[]").Nullable()
            .From("timestamp").To("number[]").Nullable()
            .From("uniqueidentifier").To("string").Nullable()
            .From("float").To("number").Nullable();
            return(typeMapping);
        }
コード例 #30
0
        static bool TryAddPropertyFromAttribute(Type type, ITypeMapping typeMapping, ICollection <XAttribute> attributeList, PropertyInfo property, IPropertyStrategy propertyStrategy, string name)
        {
            var attribute = TakeAttribute(attributeList, name);

            if (attribute == null)
            {
                return(false);
            }

            if (propertyStrategy.Mapper != null)
            {
                throw new AutoConfigMappingException(
                          string.Format(
                              "Custom IMapper '{0}' was configured for mapping property '{1}' of '{2}'. A custom IMapper cannot be specified when mapping from an attribute.",
                              propertyStrategy.Mapper, property.Name, type));
            }

            var propertyMapping = new MappingFromAttribute(attribute, property);

            typeMapping.Include(propertyMapping);

            return(true);
        }
コード例 #31
0
        private bool GetServerMapping()
        {
            if (GetServerMappingFunc == null)
            {
                return(false);
            }

            if (_lastMappingUpdate.HasValue && _lastMappingUpdate.Value > DateTime.UtcNow.SubtractMinutes(1))
            {
                return(false);
            }

            try {
                _serverMapping     = GetServerMappingFunc();
                _lastMappingUpdate = DateTime.UtcNow;
                _logger.LogInformation("Got server mapping");

                return(true);
            } catch (Exception ex) {
                _logger.LogError(ex, "Error getting server mapping: " + ex.Message);
                return(false);
            }
        }
コード例 #32
0
ファイル: TypeRegister.cs プロジェクト: BrunoCaimar/Drikka
 /// <summary>
 /// Set the mapping for a type
 /// </summary>
 /// <param name="value">TypeMapping</param>
 public void Set(ITypeMapping value)
 {
     this._mapping.Add(value.MappedType, value);
 }
コード例 #33
0
		public virtual void Visit(ITypeMapping mapping) { }
コード例 #34
0
		public void Accept(ITypeMapping mapping)
		{
			if (mapping == null) return;
			this._visitor.Visit(mapping);
			this.Accept(mapping.Properties);
		}