Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<GlobalPackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.15.0" />
<GlobalPackageReference Include="Roslynator.CodeFixes" Version="4.15.0" />
<GlobalPackageReference Include="Roslynator.Refactorings" Version="4.15.0" />
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="10.27.0.140913" />
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="10.30.0.144632" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.9.0" />
Expand Down
2 changes: 2 additions & 0 deletions src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public CSharpCodeBuilder Append(char[]? value)
/// <param name="length">The number of characters to append.</param>
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <remarks>If the pointer is null or length is negative, the method returns without appending anything.</remarks>
#pragma warning disable S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads
public unsafe CSharpCodeBuilder Append(char* value, int length)
{
if (value == null || length < 0)
Expand All @@ -135,6 +136,7 @@ public unsafe CSharpCodeBuilder Append(char* value, int length)
_ = _builder.Append(value, length);
return this;
}
#pragma warning restore S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads

/// <summary>
/// Appends a read-only memory of characters to the current builder.
Expand Down
2 changes: 2 additions & 0 deletions src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendIf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public CSharpCodeBuilder AppendIf(bool condition, char[]? value, int startIndex,
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <remarks>If the pointer is null or length is negative, the method returns without appending anything.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#pragma warning disable S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads
public unsafe CSharpCodeBuilder AppendIf(bool condition, char* value, int length) =>
condition ? Append(value, length) : this;
#pragma warning restore S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads

/// <summary>
/// Appends a read-only memory of characters to the current builder if the specified condition is true.
Expand Down
2 changes: 2 additions & 0 deletions src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public CSharpCodeBuilder AppendLine(char[]? value, int startIndex, int charCount
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <remarks>If the pointer is null or length is negative, only the line terminator is appended.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#pragma warning disable S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads
public unsafe CSharpCodeBuilder AppendLine(char* value, int length) => Append(value, length).AppendLine();
#pragma warning restore S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads

/// <summary>
/// Appends a character followed by a line terminator to the current builder.
Expand Down
2 changes: 2 additions & 0 deletions src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLineIf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ public CSharpCodeBuilder AppendLineIf(bool condition, char[]? value, int startIn
/// <returns>The current <see cref="CSharpCodeBuilder"/> instance to allow for method chaining.</returns>
/// <remarks>If the pointer is null or length is negative, the method returns without appending anything.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#pragma warning disable S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads
public unsafe CSharpCodeBuilder AppendLineIf(bool condition, char* value, int length) =>
condition ? AppendLine(value, length) : this;
#pragma warning restore S6640 // Unsafe code is intentional to support pointer-based, high-performance overloads

/// <summary>
/// Appends a character followed by a line terminator to the current builder if the specified condition is true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ public async Task AppendIf_CharPointer_Condition_True_Should_Append_Characters()
var builder = new CSharpCodeBuilder(10);
var chars = "abc".ToCharArray();

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = chars)
{
_ = builder.AppendIf(true, ptr, chars.Length);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

_ = await Assert.That(builder.ToString()).IsEqualTo("abc");
}
Expand All @@ -223,13 +225,15 @@ public async Task AppendIf_CharPointer_Condition_False_Should_Not_Append()
var builder = new CSharpCodeBuilder(10);
var chars = "abc".ToCharArray();

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = chars)
{
_ = builder.AppendIf(false, ptr, chars.Length);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

_ = await Assert.That(builder.ToString()).IsEqualTo("");
}
Expand All @@ -241,13 +245,15 @@ public async Task AppendIf_CharPointer_Should_Return_Same_Instance()
var chars = "abc".ToCharArray();
CSharpCodeBuilder result;

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = chars)
{
result = builder.AppendIf(true, ptr, chars.Length);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

_ = await Assert.That(result).IsEqualTo(builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ public async Task AppendLine_Unsafe_CharPointer_Should_Append_Characters_With_Ne
CSharpCodeBuilder result;
string builderResult;

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = text)
{
result = builder.AppendLine(ptr, text.Length);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

builderResult = builder.ToString();
_ = await Assert.That(result).IsEqualTo(builder);
Expand All @@ -226,10 +228,12 @@ public async Task AppendLine_Unsafe_CharPointer_Null_Should_Append_Only_Newline(
CSharpCodeBuilder result;
string builderResult;

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
result = builder.AppendLine(null, 0);
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

builderResult = builder.ToString();
_ = await Assert.That(result).IsEqualTo(builder);
Expand All @@ -244,13 +248,15 @@ public async Task AppendLine_Unsafe_CharPointer_Negative_Length_Should_Append_On
CSharpCodeBuilder result;
string builderResult;

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = text)
{
result = builder.AppendLine(ptr, -1);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

builderResult = builder.ToString();
_ = await Assert.That(result).IsEqualTo(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ public async Task AppendLineIf_CharPointer_Condition_True_Should_Append_Characte
var builder = new CSharpCodeBuilder(10);
var chars = "abc".ToCharArray();

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = chars)
{
_ = builder.AppendLineIf(true, ptr, chars.Length);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

_ = await Assert.That(builder.ToString()).IsEqualTo("abc" + Environment.NewLine);
}
Expand All @@ -271,13 +273,15 @@ public async Task AppendLineIf_CharPointer_Condition_False_Should_Not_Append()
var builder = new CSharpCodeBuilder(10);
var chars = "abc".ToCharArray();

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = chars)
{
_ = builder.AppendLineIf(false, ptr, chars.Length);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

_ = await Assert.That(builder.ToString()).IsEqualTo("");
}
Expand All @@ -289,13 +293,15 @@ public async Task AppendLineIf_CharPointer_Should_Return_Same_Instance()
var chars = "abc".ToCharArray();
CSharpCodeBuilder result;

#pragma warning disable S6640 // Unsafe code is intentional for pointer-based test scenarios
unsafe
{
fixed (char* ptr = chars)
{
result = builder.AppendLineIf(true, ptr, chars.Length);
}
}
#pragma warning restore S6640 // Unsafe code is intentional for pointer-based test scenarios

_ = await Assert.That(result).IsEqualTo(builder);
}
Expand Down