mirror of
https://github.com/AlexMacocian/Sybil.git
synced 2026-07-15 15:19:59 +00:00
Support raw arguments for attributes
This commit is contained in:
@@ -35,6 +35,7 @@ public sealed class TestClass<T> : BaseTestClass, IInterface where T : new(), cl
|
||||
return this.fieldString;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization | MethodImplOptions.PreserveSig)]
|
||||
public string GetSomething();
|
||||
}";
|
||||
|
||||
@@ -101,6 +102,8 @@ public sealed class TestClass<T> : BaseTestClass, IInterface where T : new(), cl
|
||||
.WithMethod(
|
||||
SyntaxBuilder.CreateMethod("string", "GetSomething")
|
||||
.WithModifier("public")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("MethodImpl")
|
||||
.WithRawArgument("MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization | MethodImplOptions.PreserveSig"))
|
||||
.WithNoBody())))
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.5.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -10,6 +10,7 @@ public class AttributeBuilderTests
|
||||
private const string AttributeName = "SomeAttribute";
|
||||
private const string PropertyName = "SomeProperty";
|
||||
private const string StringValue = "SomeString";
|
||||
private const string RawArgument = "MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization | MethodImplOptions.PreserveSig";
|
||||
private const int IntValue = 1;
|
||||
private const uint UintValue = 1U;
|
||||
private const long LongValue = 1L;
|
||||
@@ -51,6 +52,7 @@ public class AttributeBuilderTests
|
||||
private const string AttributeWithBoolTrueValue = $"{AttributeName}(true)";
|
||||
private const string AttributeWithBoolFalseValue = $"{AttributeName}(false)";
|
||||
private const string AttributeWithNullValue = $"{AttributeName}(null)";
|
||||
private const string AttributeWithRawArgument = $"{AttributeName}(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization | MethodImplOptions.PreserveSig)";
|
||||
|
||||
private readonly AttributeBuilder attributeBuilder = SyntaxBuilder.CreateAttribute(AttributeName);
|
||||
|
||||
@@ -433,4 +435,12 @@ public class AttributeBuilderTests
|
||||
|
||||
result.Should().Be(AttributeWithNullValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithRawArgument_WithRawValue_ReturnsExpected()
|
||||
{
|
||||
var result = this.attributeBuilder.WithRawArgument(RawArgument).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithRawArgument);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.5.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -408,6 +408,15 @@ namespace Sybil
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithRawArgument(string rawArgument)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.ParseExpression(rawArgument)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeSyntax Build()
|
||||
{
|
||||
return this.AttributeSyntax
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.8.3</Version>
|
||||
<Version>0.8.4</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user