コード例 #1
0
        private void WriteSetters(ISourceWriter writer)
        {
            foreach (var setter in this.Setters)
            {
                writer.BlankLine();
                setter.WriteDeclaration(writer);
            }

            writer.BlankLine();
        }
コード例 #2
0
        public static void Write(IGenerationModel generationModel, ISourceWriter writer)
        {
            writeClassDeclaration(generationModel, writer);
            writeFields(generationModel, writer);

            writer.BlankLine();

            writeConstructor(generationModel, writer);

            writer.BlankLine();

            writeHandleMethod(generationModel, writer);

            writer.FinishBlock();
        }
コード例 #3
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteLine($"var {Name} = {RoutingFrames.Segments}[{Position}];");
            writer.BlankLine();

            Next?.GenerateCode(method, writer);
        }
コード例 #4
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteLine($"var {Name} = ({Variable.VariableType.FullNameInCode()}){Context.Usage}.Request.RouteValues[\"{Variable.Usage}\"];");
            writer.BlankLine();

            Next?.GenerateCode(method, writer);
        }
コード例 #5
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.BlankLine();
     writer.WriteComment($"From {nameof(BuildClientFrame)}");
     writer.Write($"var {Client.Usage} = {_factory.Usage}.{nameof(IHttpClientFactory.CreateClient)}(\"{_interfaceType.Name}\");");
     Next?.GenerateCode(method, writer);
 }
コード例 #6
0
ファイル: GeneratedMessage.cs プロジェクト: tmpreston/jasper
 public void WriteAnnotations(ISourceWriter writer)
 {
     writer.WriteLine($"[{typeof(MessageAliasAttribute).FullName.TrimEnd("Attribute".ToCharArray())}(\"{MessageAlias}\")]");
     writer.WriteLine($"[{typeof(VersionAttribute).FullName.TrimEnd("Attribute".ToCharArray())}(\"{Version}\")]");
     writer.WriteLine($"public partial class {ClassName} {{}}");
     writer.BlankLine();
 }
コード例 #7
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (CommentText.IsNotEmpty())
            {
                writer.WriteComment(CommentText);
            }

            var invokeMethod = InvocationCode(method);

            if (shouldWriteInUsingBlock(method))
            {
                writer.UsingBlock($"{returnActionCode(method)}{invokeMethod}", w => Next?.GenerateCode(method, writer));
            }
            else
            {
                writer.Write($"{returnActionCode(method)}{invokeMethod};");

                // This is just to make the generated code a little
                // easier to read
                if (CommentText.IsNotEmpty())
                {
                    writer.BlankLine();
                }

                Next?.GenerateCode(method, writer);
            }
        }
コード例 #8
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.BlankLine();
     writer.WriteComment($"From {nameof(FillUrlFrame)}");
     writer.Write($"var {Url.Usage} = $\"{Pattern}\";");
     Next?.GenerateCode(method, writer);
 }
コード例 #9
0
        private void WriteFieldDeclarations(ISourceWriter writer, HashSet <InjectedField> args)
        {
            foreach (var field in args)
            {
                field.WriteDeclaration(writer);
            }

            writer.BlankLine();
        }
コード例 #10
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var serializeMethodName = $"{typeof(JsonConvert).FullNameInCode()}.{nameof(JsonConvert.SerializeObject)}";

            writer.BlankLine();
            writer.WriteComment($"From {nameof(SerializeJsonFrame)}");
            writer.Write($"var {Json.Usage} = {serializeMethodName}({_input.Usage});");
            Next?.GenerateCode(method, writer);
        }
コード例 #11
0
        private static void writeFields(IGenerationModel generationModel, ISourceWriter writer)
        {
            foreach (var field in generationModel.Fields)
            {
                field.WriteDeclaration(writer);
            }

            writer.BlankLine();
        }
コード例 #12
0
ファイル: DeserializeObjectFrame.cs プロジェクト: yuzd/lamar
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var responseContent = $"await {_response.Usage}.Content.ReadAsStringAsync()";
            var methodName      = $"{typeof(JsonConvert).FullNameInCode()}.{nameof(JsonConvert.DeserializeObject)}";

            writer.BlankLine();
            writer.WriteComment($"From {nameof(DeserializeObjectFrame)}");
            writer.Write($"var {ReturnValue.Usage} = {methodName}<{ReturnValue.VariableType.FullNameInCode()}>({responseContent});");
            Next?.GenerateCode(method, writer);
        }
コード例 #13
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (CommentText.IsNotEmpty())
            {
                writer.WriteComment(CommentText);
            }

            var invokeMethod = invocationCode();

            var returnValue = "";

            if (IsAsync)
            {
                #if NET461 || NET48
                if (method.AsyncMode == AsyncMode.AsyncTask)
                {
                    invokeMethod = invokeMethod + ".ConfigureAwait(false)";
                }
#endif
                returnValue = method.AsyncMode == AsyncMode.ReturnFromLastNode ? "return " : "await ";
            }

            var isDisposable = false;
            if (shouldAssignVariableToReturnValue(method))
            {
#if !NET4x
                returnValue = ReturnVariable.VariableType.IsValueTuple() ? $"{ReturnVariable.Usage} = {returnValue}" : $"{ReturnVariable.AssignmentUsage} = {returnValue}";
                #else
                returnValue = $"{ReturnVariable.AssignmentUsage} = {returnValue}";
#endif


                isDisposable = ReturnVariable.VariableType.CanBeCastTo <IDisposable>();
            }

            if (isDisposable && DisposalMode == DisposalMode.UsingBlock)
            {
                writer.UsingBlock($"{returnValue}{invokeMethod}", w => Next?.GenerateCode(method, writer));
            }
            else
            {
                writer.Write($"{returnValue}{invokeMethod};");

                // This is just to make the generated code a little
                // easier to read
                if (CommentText.IsNotEmpty())
                {
                    writer.BlankLine();
                }

                Next?.GenerateCode(method, writer);
            }
        }
コード例 #14
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var alias = RoutingFrames.TypeOutputs[Variable.VariableType];

            writer.WriteLine($"{alias} {Variable.Usage};");
            writer.Write($"BLOCK:if (!{alias}.TryParse(segments[{Position}], out {Variable.Usage}))");
            writer.WriteLine($"{RouteGraph.Context}.{nameof(HttpContext.Response)}.{nameof(HttpResponse.StatusCode)} = 400;");
            writer.WriteLine(method.ToExitStatement());
            writer.FinishBlock();

            writer.BlankLine();
            Next?.GenerateCode(method, writer);
        }
コード例 #15
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (_createsSession)
            {
                writer.BlankLine();
                writer.WriteComment("Open a new document session");
                writer.Write(
                    $"BLOCK:using (var {Session.Usage} = {_store.Usage}.{nameof(IDocumentStore.LightweightSession)}())");
            }

            if (_context != null && _isUsingPersistence)
            {
                writer.Write(
                    $"await {typeof(MessageContextExtensions).FullName}.{nameof(MessageContextExtensions.EnlistInTransaction)}({_context.Usage}, {Session.Usage});");
            }

            foreach (var loaded in _loadedDocs)
            {
                loaded.Write(writer, Session);
            }

            Next?.GenerateCode(method, writer);


            foreach (var saved in _saved)
            {
                writer.Write($"{Session.Usage}.{nameof(IDocumentSession.Store)}({saved.Usage});");
            }

            writer.BlankLine();
            writer.WriteComment("Commit the unit of work");
            writer.Write($"await {Session.Usage}.{nameof(IDocumentSession.SaveChangesAsync)}();");

            if (_createsSession)
            {
                writer.FinishBlock();
            }
        }
コード例 #16
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var alias = RouteArgument.TypeOutputs[Variable.VariableType];

            writer.WriteLine($"{alias} {Variable.Usage};");
            writer.Write($"BLOCK:if (!{alias}.TryParse((string){Context.Usage}.Request.RouteValues[\"{Variable.Usage}\"], out {Variable.Usage}))");
            writer.WriteLine(
                $"{RouteGraph.Context}.{nameof(HttpContext.Response)}.{nameof(HttpResponse.StatusCode)} = 400;");
            writer.WriteLine(method.ToExitStatement());
            writer.FinishBlock();

            writer.BlankLine();
            Next?.GenerateCode(method, writer);
        }
コード例 #17
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteComment("Check if the saga has been completed");
            writer.Write($"BLOCK:if ({_handler.Usage}.{nameof(StatefulSagaOf<string>.IsCompleted)})");
            writer.WriteComment("Delete the saga state entity");
            writer.Write($"{_context.Usage}.{nameof(DbContext.Remove)}({_state.Usage});");
            writer.FinishBlock();
//            writer.Write("BLOCK:else");
//            writer.WriteComment("Persist the saga state entity");
//            writer.Write($"{_context.Usage}.{nameof(DbContext.Add)}({_state.Usage});");
//            writer.FinishBlock();

            writer.BlankLine();

            Next?.GenerateCode(method, writer);
        }
コード例 #18
0
ファイル: GeneratedType.cs プロジェクト: vlisovych/lamar
        public void Write(ISourceWriter writer)
        {
            writeDeclaration(writer);

            if (AllInjectedFields.Any())
            {
                writeFieldDeclarations(writer, AllInjectedFields);
                writeConstructorMethod(writer, AllInjectedFields);
            }

            writeSetters(writer);


            foreach (var method in _methods.Where(x => x.WillGenerate()))
            {
                writer.BlankLine();
                method.WriteMethod(writer);
            }

            writer.FinishBlock();
        }
コード例 #19
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.Write(
                $"await {typeof(JasperEnvelopeEntityFrameworkCoreExtensions).FullName}.{nameof(JasperEnvelopeEntityFrameworkCoreExtensions.EnlistInTransaction)}({_context.Usage}, {Context.Usage});");

            foreach (var loaded in _loadedDocs)
            {
                loaded.Write(writer, Context);
            }

            Next?.GenerateCode(method, writer);


            foreach (var saved in _saved)
            {
                writer.Write($"{Context.Usage}.{nameof(DbContext.Add)}({saved.Usage});");
            }

            writer.BlankLine();
            writer.WriteComment("Commit the unit of work");
            writer.Write($"await {Context.Usage}.{nameof(DbContext.SaveChangesAsync)}();");
        }
コード例 #20
0
ファイル: GeneratedType.cs プロジェクト: gasyleiss/lamar
        public void Write(ISourceWriter writer)
        {
            writeDeclaration(writer);

            var args = Args();

            if (args.Any())
            {
                writeFieldDeclarations(writer, args);
                writeConstructorMethod(writer, args);
            }

            writeSetters(writer);


            foreach (var method in _methods)
            {
                writer.BlankLine();
                method.WriteMethod(writer);
            }

            writer.FinishBlock();
        }