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); }
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); }
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(); }
/// <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); } }
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); }
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); }
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); }
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(); }
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); }
private void WriteReturnStatement(ISourceWriter writer) { if ((this.AsyncMode == AsyncMode.ReturnCompletedTask || this.AsyncMode == AsyncMode.None) && this.ReturnType == typeof(Task)) { writer.WriteLine("return Task.CompletedTask;"); } }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine( $"var {RoutingFrames.Segments} = (string[]){RouteGraph.Context}.Items[\"{RoutingFrames.Segments}\"];"); Next?.GenerateCode(method, writer); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine($"var {Name} = {RoutingFrames.Segments}[{Position}];"); writer.BlankLine(); Next?.GenerateCode(method, writer); }
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(); }
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(); }
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); }
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); }
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); }
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); } }
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); }
// 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); } }
public override void WriteAssignment(ISourceWriter writer) { writer.WriteLine($"{this.Usage} = {this.ArgumentName}Factory.{nameof(ILoggerFactory.CreateLogger)}(\"{this._name}\");"); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine($"{_response.Usage}.{nameof(HttpResponse.StatusCode)} = {_usage};"); Next?.GenerateCode(method, writer); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { base.GenerateCode(method, writer); writer.WriteLine($"{_operations.Usage}.Store({ReturnVariable.Usage});"); }
public void WriteDeclaration(ISourceWriter writer) { writer.WriteLine($"private readonly {this.VariableType.FullNameInCode()} {this.Usage};"); }
public virtual void WriteAssignment(ISourceWriter writer) { writer.WriteLine($"{this.Usage} = {this.ArgumentName};"); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine($"var {NowVariable.Now} = {typeof(DateTimeOffset).FullName}.{nameof(DateTimeOffset.UtcNow)};"); Next?.GenerateCode(method, writer); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine($"{Variable.VariableType.FullNameInCode()} {Variable.Usage} = null;"); Next?.GenerateCode(method, writer); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine($"return {_one.Usage} * {_two.Usage};"); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine($"{_response.Usage}.Headers[\"{Name}\"] = \"{Value}\";"); Next?.GenerateCode(method, writer); }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteLine("FrameThatBuildsVariable"); }