コード例 #1
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            string declaration = null;

            switch (Action)
            {
            case CreateAggregateAction.Assign:
                declaration = $"{Aggregate.Usage} =";
                break;

            case CreateAggregateAction.Initialize:
                declaration = $"var {Aggregate.Usage} =";
                break;

            case CreateAggregateAction.NullCoalesce:
                declaration = $"{Aggregate.Usage} ??=";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(Action));
            }

            if (IsAsync)
            {
                writer.WriteLine($"{declaration} await {CreateMethodCollection.MethodName}({FirstEventExpression}, {_session.Usage}, {_cancellation.Usage});");
            }
            else
            {
                writer.WriteLine($"{declaration} {CreateMethodCollection.MethodName}({FirstEventExpression}, {_session.Usage});");
            }

            Next?.GenerateCode(method, writer);
        }
コード例 #2
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (InsideForEach)
            {
                writer.Write("BLOCK:foreach (var @event in events)");
            }

            if (IsAsync)
            {
                writer.WriteLine(
                    $"{_aggregate.Usage} = await {ApplyMethodCollection.MethodName}(@event, {_aggregate.Usage}, {_session.Usage}, {_cancellation.Usage});");
            }
            else
            {
                writer.WriteLine(
                    $"{_aggregate.Usage} = {ApplyMethodCollection.MethodName}(@event, {_aggregate.Usage}, {_session.Usage});");
            }

            if (InsideForEach)
            {
                writer.FinishBlock();
            }

            Next?.GenerateCode(method, writer);
        }
コード例 #3
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();
 }
コード例 #4
0
 /// <summary>
 /// Writes either "return;" or "return Task.CompletedTask;" into the code
 /// for synchronous or asynchronous methods
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="method"></param>
 public static void WriteReturnStatement(this ISourceWriter writer, GeneratedMethod method)
 {
     if (method.AsyncMode == AsyncMode.AsyncTask)
     {
         writer.WriteLine("return;");
     }
     else
     {
         writer.WriteLine(returnCompletedTask);
     }
 }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            if (_aggregate == null)
            {
                writer.WriteLine($"return new {_slot.ReturnType.FullNameInCode()}({_arg.Usage});");
            }
            else
            {
                writer.WriteLine($"{_aggregate.Usage} ??= new {_slot.ReturnType.FullNameInCode()}({_arg.Usage});");
            }


            Next?.GenerateCode(method, writer);
        }
コード例 #8
0
        protected void LoopAttributes(IMethodVariables variables, ISourceWriter writer, string methodCall)
        {
            var resultsVariable = variables.FindVariable(typeof(ValidationFailures));
            var attributeType   = typeof(T).FullNameInCode();
            var awaitMethod     = this.IsAsync ? "await" : string.Empty;

            writer.Comment($"{this._property.PropertyInfoVariable} == {this._property.PropertyInfoVariable.Property.DeclaringType.Name}.{this._property.PropertyInfoVariable.Property.Name}");
            writer.Block($"foreach (var attribute in {this._property.PropertyAttributesVariable})");
            writer.Block($"if (attribute is {attributeType} x)");
            writer.WriteLine($"var result = {awaitMethod} x.{methodCall};");
            writer.Block($"if (result != {Variable.StaticFrom<ValidationResult>(nameof(ValidationResult.Success))})");
            writer.WriteLine($"{resultsVariable}.{nameof(ValidationFailures.AddFailure)}(result);");
            writer.FinishBlock();
            writer.FinishBlock();
            writer.FinishBlock();
        }
コード例 #9
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);
        }
コード例 #10
0
 private void WriteReturnStatement(ISourceWriter writer)
 {
     if ((this.AsyncMode == AsyncMode.ReturnCompletedTask || this.AsyncMode == AsyncMode.None) && this.ReturnType == typeof(Task))
     {
         writer.WriteLine("return Task.CompletedTask;");
     }
 }
コード例 #11
0
ファイル: SegmentsFrame.cs プロジェクト: SVemulapalli/jasper
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteLine(
                $"var {RoutingFrames.Segments} = (string[]){RouteGraph.Context}.Items[\"{RoutingFrames.Segments}\"];");

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

            Next?.GenerateCode(method, writer);
        }
コード例 #13
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            Maybe.GenerateCode(method, writer);
            writer.Write($"BLOCK:if ({Maybe.ReturnVariable.Usage})");

            writer.WriteLine($"return null;");

            writer.FinishBlock();
        }
コード例 #14
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            Maybe.GenerateCode(method, writer);
            writer.Write($"BLOCK:if ({Maybe.ReturnVariable.Usage})");

            writer.WriteLine($"return {_storage.Usage}.DeleteForDocument({_aggregate.Usage}, {_tenant.Usage});");

            writer.FinishBlock();
        }
コード例 #15
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.Write($"var {Variable.Usage} = ({Variable.VariableType.FullNameInCode()}){_setter.Usage}(({typeof(TContainer).FullNameInCode()}){_scope.Usage});");

            if (!Variable.VariableType.IsPrimitive && !Variable.VariableType.IsEnum && Variable.VariableType != typeof(string))
            {
                writer.WriteLine($"{_scope.Usage}.{nameof(Scope.TryAddDisposable)}({Variable.Usage});");
            }

            Next?.GenerateCode(method, writer);
        }
コード例 #16
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            IfStyle.Open(writer, null);

            writer.WriteLine(_returnType.HasDefaultConstructor()
                ? $"return new {_returnType.FullNameInCode()}();"
                : $"throw new {typeof(InvalidOperationException).FullNameInCode()}(\"There is no default constructor for {_returnType.FullNameInCode()}\");");

            IfStyle.Close(writer);

            Next?.GenerateCode(method, writer);
        }
コード例 #17
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            IfStyle.Open(writer, null);

            if (_constructor == null)
            {
                writer.WriteLine($"throw new {typeof(InvalidOperationException).FullNameInCode()}(\"There is no default constructor for {_returnType.FullNameInCode()}\");");
            }
            else if (_setter != null)
            {
                writer.WriteLine("return AggregateBuilder();");
            }
            else
            {
                writer.WriteLine($"return new {_returnType.FullNameInCode()}();");
            }

            IfStyle.Close(writer);

            Next?.GenerateCode(method, writer);
        }
コード例 #18
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var creation = $"var {_output.Usage} = new {_output.VariableType.FullName.Replace("+", ".")}()";

            if (_output.VariableType.CanBeCastTo <IDisposable>())
            {
                writer.UsingBlock(creation, w => Next?.GenerateCode(method, w));
            }
            else
            {
                writer.WriteLine(creation + ";");
                Next?.GenerateCode(method, writer);
            }
        }
コード例 #19
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteLine($"{_aggregateType.FullNameInCode()} {Aggregate.Usage} = default({_aggregateType.FullNameInCode()});");
            writer.Write($"BLOCK:if ({_slice.Usage}.{nameof(StreamAction.ActionType)} == {Constant.ForEnum(StreamActionType.Start).Usage})");

            _create.Action = CreateAggregateAction.Assign;
            _create.GenerateCode(method, writer);

            writer.FinishBlock();

            writer.Write("BLOCK:else");
            _loadMethod.GenerateCode(method, writer);
            _create.Action = CreateAggregateAction.NullCoalesce;
            _create.GenerateCode(method, writer);
            writer.FinishBlock();

            Next?.GenerateCode(method, writer);
        }
コード例 #20
0
ファイル: NoArgConstructor.cs プロジェクト: gasyleiss/lamar
        // You have to override this method
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var creation = $"var {Output.Usage} = new {Output.VariableType.FullNameInCode()}()";

            if (Output.VariableType.CanBeCastTo <IDisposable>())
            {
                // there is an ISourceWriter shortcut for this, but this makes
                // a better code demo;)
                writer.Write($"BLOCK:using ({creation})");
                Next?.GenerateCode(method, writer);
                writer.FinishBlock();
            }
            else
            {
                writer.WriteLine(creation + ";");
                Next?.GenerateCode(method, writer);
            }
        }
コード例 #21
0
 public override void WriteAssignment(ISourceWriter writer)
 {
     writer.WriteLine($"{this.Usage} = {this.ArgumentName}Factory.{nameof(ILoggerFactory.CreateLogger)}(\"{this._name}\");");
 }
コード例 #22
0
ファイル: SetStatusCode.cs プロジェクト: SVemulapalli/jasper
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            writer.WriteLine($"{_response.Usage}.{nameof(HttpResponse.StatusCode)} = {_usage};");

            Next?.GenerateCode(method, writer);
        }
コード例 #23
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     base.GenerateCode(method, writer);
     writer.WriteLine($"{_operations.Usage}.Store({ReturnVariable.Usage});");
 }
コード例 #24
0
 public void WriteDeclaration(ISourceWriter writer)
 {
     writer.WriteLine($"private readonly {this.VariableType.FullNameInCode()} {this.Usage};");
 }
コード例 #25
0
 public virtual void WriteAssignment(ISourceWriter writer)
 {
     writer.WriteLine($"{this.Usage} = {this.ArgumentName};");
 }
コード例 #26
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.WriteLine($"var {NowVariable.Now} = {typeof(DateTimeOffset).FullName}.{nameof(DateTimeOffset.UtcNow)};");
     Next?.GenerateCode(method, writer);
 }
コード例 #27
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.WriteLine($"{Variable.VariableType.FullNameInCode()} {Variable.Usage} = null;");
     Next?.GenerateCode(method, writer);
 }
コード例 #28
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.WriteLine($"return {_one.Usage} * {_two.Usage};");
 }
コード例 #29
0
ファイル: SetHeader.cs プロジェクト: SVemulapalli/jasper
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.WriteLine($"{_response.Usage}.Headers[\"{Name}\"] = \"{Value}\";");
     Next?.GenerateCode(method, writer);
 }
コード例 #30
0
 public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
 {
     writer.WriteLine("FrameThatBuildsVariable");
 }