diff --git a/Directory.Packages.props b/Directory.Packages.props
index a5e6e39..afe8034 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -16,7 +16,7 @@
-
+
diff --git a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Append.cs b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Append.cs
index 7b91668..0062738 100644
--- a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Append.cs
+++ b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Append.cs
@@ -124,6 +124,7 @@ public CSharpCodeBuilder Append(char[]? value)
/// The number of characters to append.
/// The current instance to allow for method chaining.
/// If the pointer is null or length is negative, the method returns without appending anything.
+#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)
@@ -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
///
/// Appends a read-only memory of characters to the current builder.
diff --git a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendIf.cs b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendIf.cs
index fd1f07d..52cab62 100644
--- a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendIf.cs
+++ b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendIf.cs
@@ -68,8 +68,10 @@ public CSharpCodeBuilder AppendIf(bool condition, char[]? value, int startIndex,
/// The current instance to allow for method chaining.
/// If the pointer is null or length is negative, the method returns without appending anything.
[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
///
/// Appends a read-only memory of characters to the current builder if the specified condition is true.
diff --git a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLine.cs b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLine.cs
index 3079376..070bc01 100644
--- a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLine.cs
+++ b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLine.cs
@@ -101,7 +101,9 @@ public CSharpCodeBuilder AppendLine(char[]? value, int startIndex, int charCount
/// The current instance to allow for method chaining.
/// If the pointer is null or length is negative, only the line terminator is appended.
[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
///
/// Appends a character followed by a line terminator to the current builder.
diff --git a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLineIf.cs b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLineIf.cs
index bf8827f..d27bec6 100644
--- a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLineIf.cs
+++ b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.AppendLineIf.cs
@@ -103,8 +103,10 @@ public CSharpCodeBuilder AppendLineIf(bool condition, char[]? value, int startIn
/// The current instance to allow for method chaining.
/// If the pointer is null or length is negative, the method returns without appending anything.
[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
///
/// Appends a character followed by a line terminator to the current builder if the specified condition is true.
diff --git a/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendIf.cs b/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendIf.cs
index cacf52c..f38fcc3 100644
--- a/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendIf.cs
+++ b/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendIf.cs
@@ -206,6 +206,7 @@ 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)
@@ -213,6 +214,7 @@ public async Task AppendIf_CharPointer_Condition_True_Should_Append_Characters()
_ = 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");
}
@@ -223,6 +225,7 @@ 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)
@@ -230,6 +233,7 @@ public async Task AppendIf_CharPointer_Condition_False_Should_Not_Append()
_ = 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("");
}
@@ -241,6 +245,7 @@ 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)
@@ -248,6 +253,7 @@ public async Task AppendIf_CharPointer_Should_Return_Same_Instance()
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);
}
diff --git a/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLine.cs b/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLine.cs
index bbbcb08..86c8bf2 100644
--- a/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLine.cs
+++ b/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLine.cs
@@ -206,6 +206,7 @@ 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)
@@ -213,6 +214,7 @@ public async Task AppendLine_Unsafe_CharPointer_Should_Append_Characters_With_Ne
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);
@@ -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);
@@ -244,6 +248,7 @@ 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)
@@ -251,6 +256,7 @@ public async Task AppendLine_Unsafe_CharPointer_Negative_Length_Should_Append_On
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);
diff --git a/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLineIf.cs b/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLineIf.cs
index 8ede0b6..61f02d7 100644
--- a/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLineIf.cs
+++ b/tests/NetEvolve.CodeBuilder.Tests.Unit/CSharpCodeBuilderTests.AppendLineIf.cs
@@ -254,6 +254,7 @@ 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)
@@ -261,6 +262,7 @@ public async Task AppendLineIf_CharPointer_Condition_True_Should_Append_Characte
_ = 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);
}
@@ -271,6 +273,7 @@ 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)
@@ -278,6 +281,7 @@ public async Task AppendLineIf_CharPointer_Condition_False_Should_Not_Append()
_ = 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("");
}
@@ -289,6 +293,7 @@ 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)
@@ -296,6 +301,7 @@ public async Task AppendLineIf_CharPointer_Should_Return_Same_Instance()
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);
}