public void Visit(IVisitor visitor, CMethod method) { NewMethod(method); foreach (var methodAttribute in method.Attribute) { methodAttribute.Accept(visitor); } var modifier = !method.SignatureOnly ? method.AccessModifier.GetString() + " " : string.Empty; var abstractText = method.IsAbstract ? "abstract " : string.Empty; var overrideText = method.IsOverride ? "override " : string.Empty; var @static = method.IsStatic ? "static " : string.Empty; var asyncText = method.IsAsync ? "async " : string.Empty; var thisText = method.IsExtensionMethod ? "this " : string.Empty; _codeWriter.Write( $"{modifier}{@static}{abstractText}{overrideText}{asyncText}{method.ReturnType} {method.MethodName}({thisText}"); var first = true; var paramIndex = 0; _codeWriter.SaveIndent(); var methodTextLength = method.TextLength; foreach (var param in method.Parameter) { if (!first) { _codeWriter.Write(", "); } if (methodTextLength > 100 && method.Parameter.Count > 1) //attempt to Mirror Resharper's rules { //wrap the parameters to next line _codeWriter.WriteLine(""); if (first) { _codeWriter.Indent(); } } visitor.VisitCParameter(param); first = false; paramIndex++; } _codeWriter.Write(")"); _codeWriter.RestoreIndent(); if (method.SignatureOnly || method.IsAbstract) { _codeWriter.WriteLine(";"); } else if (method.UseExpressionDefinition) { _codeWriter.WriteLine($" => {method.CodeSnippet}"); } else { _codeWriter.WriteLine(string.Empty); _codeWriter.WriteLine("{"); _codeWriter.SaveIndent(); _codeWriter.Indent(); if (!string.IsNullOrEmpty(method.CodeSnippetFile) || !string.IsNullOrEmpty(method.CodeSnippet)) { if (!string.IsNullOrEmpty(method.CodeSnippet)) { _codeWriter.WriteLine(method.CodeSnippet); } if (!string.IsNullOrEmpty(method.CodeSnippetFile)) { var snippetService = new SnippetService(); _codeWriter.WriteLine(snippetService.GetCodeSnippet(method.MethodName, method.CodeSnippetFile)); } } else if (method.ReturnType != "void") { _codeWriter.WriteLine("throw new NotImplementedException();"); } _codeWriter.Unindent(); _codeWriter.RestoreIndent(); _codeWriter.WriteLine("}"); // _codeWriter.WriteLine(); } }
public void Visit(IVisitor visitor, CConstructor constructor) { string staticString = constructor.IsStatic ? "static " : string.Empty; var accessModifier = constructor.IsStatic ? string.Empty : $"{constructor.AccessModifier.GetString()} "; _codeWriter.Write($"{accessModifier}{staticString}{constructor.ConstructorName}("); var first = true; foreach (var param in constructor.Parameter) { if (!first) { _codeWriter.Write(", "); } visitor.VisitCParameter(param); first = false; } _codeWriter.Write(")"); var passToBaseClass = constructor.Parameter.Where(p => p.PassToBaseClass); if (passToBaseClass.Any()) { _codeWriter.Write(" : base("); var firstParameter = true; foreach (var parameter in passToBaseClass) { if (!firstParameter) { _codeWriter.Write(", "); } firstParameter = false; _codeWriter.Write($"{parameter.ParameterName}"); } _codeWriter.Write(")"); } { _codeWriter.WriteLine(string.Empty); _codeWriter.WriteLine("{"); _codeWriter.Indent(); if (!string.IsNullOrEmpty(constructor.CodeSnippetFile) || !string.IsNullOrEmpty(constructor.CodeSnippet)) { if (!string.IsNullOrEmpty(constructor.CodeSnippet)) { _codeWriter.WriteLine(constructor.CodeSnippet); } if (!string.IsNullOrEmpty(constructor.CodeSnippetFile)) { var snippetService = new SnippetService(); _codeWriter.WriteLine(snippetService.GetCodeSnippet(constructor.ConstructorName, constructor.CodeSnippetFile)); } } else { //_codeWriter.WriteLine("throw new NotImplementedException();"); } _codeWriter.Unindent(); _codeWriter.WriteLine("}"); _codeWriter.WriteLine(); } }