mirror of
https://github.com/AlexMacocian/Sybil.git
synced 2026-07-15 15:19:59 +00:00
Fix multi-line SyntaxBody
This commit is contained in:
@@ -20,6 +20,7 @@ namespace TestNamespace
|
||||
TestClass(string fieldString) : base(fieldString)
|
||||
{
|
||||
this.fieldString = fieldString ?? throw new ArgumentNullException();
|
||||
this.PropertyString = string.Empty;
|
||||
}
|
||||
|
||||
[SomeAttribute2]
|
||||
@@ -30,6 +31,7 @@ namespace TestNamespace
|
||||
[SomeAttribute4(0.5F)]
|
||||
public string GetFieldString()
|
||||
{
|
||||
this.fieldString = 0;
|
||||
return this.fieldString;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +63,7 @@ namespace TestNamespace
|
||||
SyntaxBuilder.CreateAttribute("SomeAttribute5")
|
||||
.WithNullArgument())
|
||||
.WithParameter("string", "fieldString")
|
||||
.WithBody("this.fieldString = fieldString ?? throw new ArgumentNullException();"))
|
||||
.WithBody("this.fieldString = fieldString ?? throw new ArgumentNullException();\rthis.PropertyString = string.Empty;"))
|
||||
.WithField(
|
||||
SyntaxBuilder.CreateField("string", "fieldString")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute2"))
|
||||
@@ -81,7 +83,7 @@ namespace TestNamespace
|
||||
.WithModifier("public")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute4")
|
||||
.WithArgument(0.5f))
|
||||
.WithBody("return this.fieldString;")))
|
||||
.WithBody("this.fieldString = 0;\r\nreturn this.fieldString;")))
|
||||
.Build();
|
||||
|
||||
var namespaceString = namespaceSyntax.ToFullString();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sybil
|
||||
{
|
||||
@@ -40,7 +41,7 @@ namespace Sybil
|
||||
_ = string.IsNullOrWhiteSpace(body) ? throw new ArgumentNullException(nameof(body)) : body;
|
||||
|
||||
this.ArrowExpressionClauseSyntax = null;
|
||||
this.BlockSyntax = SyntaxFactory.Block(SyntaxFactory.ParseStatement(body));
|
||||
this.BlockSyntax = SyntaxFactory.Block(body.Split('\n', '\r').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => SyntaxFactory.ParseStatement(s)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace Sybil
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(body) ? throw new ArgumentNullException(nameof(body)) : body;
|
||||
|
||||
this.ConstructorDeclarationSyntax = this.ConstructorDeclarationSyntax.WithBody(SyntaxFactory.Block(SyntaxFactory.ParseStatement(body)));
|
||||
this.ConstructorDeclarationSyntax = this.ConstructorDeclarationSyntax.WithBody(
|
||||
SyntaxFactory.Block(body.Split('\n', '\r').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => SyntaxFactory.ParseStatement(s))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -87,8 +87,13 @@ namespace Sybil
|
||||
|
||||
public MethodBuilder WithBody(string body)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(body));
|
||||
}
|
||||
|
||||
this.BlockBody = SyntaxFactory.Block(
|
||||
SyntaxFactory.ParseStatement(body));
|
||||
body.Split('\n', '\r').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => SyntaxFactory.ParseStatement(s)));
|
||||
this.ArrowExpression = null;
|
||||
|
||||
return this;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.4.0</Version>
|
||||
<Version>0.4.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user