Ejemplo n.º 1
0
        void IMetadataBuilder.BuildFunctionMetadata(FunctionMetadata metadata, MethodBuilder methodBuilder)
        {
            var attr = methodBuilder.Attribute(WellKnownTypes.LinqToDB.SqlFunctionAttribute);

            if (metadata.Name != null)
            {
                // TODO: linq2db fix
                // currently we don't have mapping API for functions that use FQN components, so we need to generate raw SQL name
                attr.Parameter(_builder.Constant(_fqnGenerator(metadata.Name.Value), true));
            }

            if (metadata.Configuration != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_Configuration, _builder.Constant(metadata.Configuration, true));
            }
            if (metadata.ServerSideOnly != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_ServerSideOnly, _builder.Constant(metadata.ServerSideOnly.Value, true));
            }
            if (metadata.PreferServerSide != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_PreferServerSide, _builder.Constant(metadata.PreferServerSide.Value, true));
            }
            if (metadata.InlineParameters != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_InlineParameters, _builder.Constant(metadata.InlineParameters.Value, true));
            }
            if (metadata.IsPredicate != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsPredicate, _builder.Constant(metadata.IsPredicate.Value, true));
            }
            if (metadata.IsAggregate != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsAggregate, _builder.Constant(metadata.IsAggregate.Value, true));
            }
            if (metadata.IsWindowFunction != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsWindowFunction, _builder.Constant(metadata.IsWindowFunction.Value, true));
            }
            if (metadata.IsPure != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsPure, _builder.Constant(metadata.IsPure.Value, true));
            }
            if (metadata.CanBeNull != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_CanBeNull, _builder.Constant(metadata.CanBeNull.Value, true));
            }
            if (metadata.IsNullable != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_IsNullable, _builder.Constant(metadata.IsNullable.Value, true));
            }

            if (metadata.ArgIndices != null && metadata.ArgIndices.Length > 0)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_ExpressionAttribute_ArgIndices, _builder.Array(WellKnownTypes.System.Int32, true, true, BuildArgIndices(metadata.ArgIndices)));
            }

            // Sql.FunctionAttribute.Precedence not generated, as we currenty don't allow expressions for function name in generator
        }
Ejemplo n.º 2
0
        public void Test4()
        {
            MethodBuilder template = MethodBuilder.Random();
            var           result   = template
                                     .Attribute <ClassDataAttribute>()
                                     .Unsafe()
                                     .Async()
                                     .Access(Natasha.Reverser.Model.AccessTypes.Public)
                                     .DefinedName("Name")
                                     .Script;

            Assert.Equal($"[Xunit.ClassDataAttribute]{Environment.NewLine}public unsafe async void Name(){{}}", result);
            Assert.Equal(typeof(Action), template.DelegateType);
        }
Ejemplo n.º 3
0
        public void Test1()
        {
            MethodBuilder template = MethodBuilder.Random();
            var           result   = template
                                     .Attribute("[Test]")
                                     .Access("public")
                                     .Modifier("static")
                                     .DefinedName("Name")
                                     .DefinedType <string>()
                                     .Script;

            Assert.Equal($"[Test]{Environment.NewLine}public static System.String Name(){{}}", result);
            Assert.Equal(typeof(Func <string>), template.DelegateType);
        }
Ejemplo n.º 4
0
        public void Test4()
        {
            MethodBuilder template = MethodBuilder.RandomDomain();
            var           result   = template
                                     .Attribute <ClassDataAttribute>()
                                     .Unsafe()
                                     .Async()
                                     .Constraint("where T : class")
                                     .Access(AccessFlags.Public)
                                     .Name("Name")
                                     .Script;

            Assert.Equal($"[Xunit.ClassDataAttribute]{Environment.NewLine}public unsafe async void Name() where T : class{{}}", result);
            Assert.Equal(typeof(Action), template.DelegateType);
        }
Ejemplo n.º 5
0
        public void Test3()
        {
            MethodBuilder template = MethodBuilder.Random();
            var           result   = template
                                     .Attribute("[Test]")
                                     .Async()
                                     .Access(Natasha.Reverser.Model.AccessTypes.Public)
                                     .DefinedName("Name")
                                     .Return(typeof(MethodBuilder))
                                     .Body("int a = 0;")
                                     .BodyAppend("return \"xm\";")
                                     .Script;

            Assert.Equal($"[Test]{Environment.NewLine}public async Natasha.Builder.MethodBuilder Name(){{int a = 0;return \"xm\";}}", result);
            Assert.Equal(typeof(Func <Natasha.Builder.MethodBuilder>), template.DelegateType);
        }
Ejemplo n.º 6
0
        public void Test2()
        {
            MethodBuilder template = MethodBuilder.Random();
            var           result   = template
                                     .Attribute("[Test][Test1]")
                                     .Access(Natasha.Reverser.Model.AccessTypes.Public)
                                     .Modifier(Natasha.Reverser.Model.Modifiers.Static)
                                     .DefinedName("Age")
                                     .Param <int>("p")
                                     .Return <int>()
                                     .Body("return 1;")
                                     .Script;

            Assert.Equal($"[Test][Test1]{Environment.NewLine}public static System.Int32 Age(System.Int32 p){{return 1;}}", result);
            Assert.Equal(typeof(Func <int, int>), template.DelegateType);
        }
Ejemplo n.º 7
0
        void IMetadataBuilder.BuildTableFunctionMetadata(TableFunctionMetadata metadata, MethodBuilder methodBuilder)
        {
            var attr = methodBuilder.Attribute(WellKnownTypes.LinqToDB.SqlTableFunctionAttribute);

            if (metadata.Name != null)
            {
                // compared to Sql.FunctionAttribute, Sql.TableFunctionAttribute provides proper FQN mapping attributes
                if (metadata.Name.Value.Name != null)
                {
                    attr.Parameter(_builder.Constant(metadata.Name.Value.Name, true));
                }
                if (metadata.Name.Value.Package != null)
                {
                    attr.Parameter(WellKnownTypes.LinqToDB.Sql_TableFunctionAttribute_Package, _builder.Constant(metadata.Name.Value.Package, true));
                }
                if (metadata.Name.Value.Schema != null)
                {
                    attr.Parameter(WellKnownTypes.LinqToDB.Sql_TableFunctionAttribute_Schema, _builder.Constant(metadata.Name.Value.Schema, true));
                }
                if (metadata.Name.Value.Database != null)
                {
                    attr.Parameter(WellKnownTypes.LinqToDB.Sql_TableFunctionAttribute_Database, _builder.Constant(metadata.Name.Value.Database, true));
                }
                if (metadata.Name.Value.Server != null)
                {
                    attr.Parameter(WellKnownTypes.LinqToDB.Sql_TableFunctionAttribute_Server, _builder.Constant(metadata.Name.Value.Server, true));
                }
            }

            if (metadata.Configuration != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_TableFunctionAttribute_Configuration, _builder.Constant(metadata.Configuration, true));
            }

            if (metadata.ArgIndices != null && metadata.ArgIndices.Length > 0)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Sql_TableFunctionAttribute_ArgIndices, _builder.Array(WellKnownTypes.System.Int32, true, true, BuildArgIndices(metadata.ArgIndices)));
            }
        }
Ejemplo n.º 8
0
 void IMetadataBuilder.BuildAssociationMetadata(AssociationMetadata metadata, MethodBuilder methodBuilder)
 {
     BuildAssociationAttribute(metadata, methodBuilder.Attribute(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute));
 }