Skip to content

Commit 345f73c

Browse files
committed
Fix warnings
1 parent 074ffa9 commit 345f73c

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

src/FastExpressionCompiler/ILReader.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#nullable disable
2+
13
#if DEBUG
24
// #define DEBUG_INTERNALS
35
#endif
@@ -7,6 +9,7 @@
79
using System.Collections;
810
using System.Collections.Generic;
911
using System.Diagnostics;
12+
using System.Globalization;
1013
using System.Reflection;
1114
using System.Reflection.Emit;
1215
using System.Text;
@@ -22,7 +25,13 @@ namespace FastExpressionCompiler.LightExpression.ILDecoder;
2225
namespace FastExpressionCompiler.ILDecoder;
2326
#endif
2427

28+
#pragma warning disable IDE0079 // Remove unnecessary suppression (like the ones below when they don't apply)
29+
#pragma warning disable IDE1006 // Naming rule violation: Identifiers should be cased correctly
30+
#pragma warning disable IDE0038 // Use pattern matching
31+
#pragma warning disable IDE0057 // Use range operator
32+
2533
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
34+
#pragma warning disable CA1305 // Specify IFormatProvider
2635

2736
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "Uses reflection on internal types and is not trim-compatible.")]
2837
public static class ILReaderFactory
@@ -109,7 +118,11 @@ public static StringBuilder ToILString(this IEnumerable<ILInstruction> ilInstruc
109118
case OperandType.InlineMethod:
110119
var m = (InlineMethodInstruction)il;
111120
var sig = m.Method.ToString();
121+
#if NET
122+
var paramStart = sig.IndexOf('(', StringComparison.Ordinal);
123+
#else
112124
var paramStart = sig.IndexOf('(');
125+
#endif
113126
var paramList = paramStart == -1 ? "()" : sig.Substring(paramStart);
114127

115128
if (m.Method is MethodInfo met)
@@ -556,8 +569,12 @@ public class MethodBaseILProvider : IILProvider
556569

557570
public MethodBaseILProvider(MethodBase method)
558571
{
572+
#if NET
573+
ArgumentNullException.ThrowIfNull(method);
574+
#else
559575
if (method == null)
560576
throw new ArgumentNullException(nameof(method));
577+
#endif
561578

562579
var methodType = method.GetType();
563580
if (methodType != _runtimeMethodInfoType & methodType != _runtimeConstructorInfoType)
@@ -613,21 +630,21 @@ public DynamicMethodILProvider(DynamicMethod method)
613630

614631
public static class ILFormatter
615632
{
616-
public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8"));
617-
public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4"));
618-
public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2"));
619-
public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.Append($"V_{ordinal}");
620-
public static StringBuilder Label(StringBuilder sb, int offset) => sb.Append($"IL_{offset:D4}");
633+
public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8", CultureInfo.InvariantCulture));
634+
public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4", CultureInfo.InvariantCulture));
635+
public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2", CultureInfo.InvariantCulture));
636+
public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.AppendFormat(CultureInfo.InvariantCulture, "V_{0}", ordinal);
637+
public static StringBuilder Label(StringBuilder sb, int offset) => sb.AppendFormat(CultureInfo.InvariantCulture, "IL_{0:D4}", offset);
621638

622639
public static StringBuilder MultipleLabels(StringBuilder sb, int[] offsets)
623640
{
624641
var length = offsets.Length;
625642
for (var i = 0; i < length; i++)
626643
{
627-
sb.AppendFormat(i == 0 ? "(" : ", ");
644+
sb.Append(i == 0 ? "(" : ", ");
628645
sb.Append(Label(sb, offsets[i]));
629646
}
630-
sb.AppendFormat(")");
647+
sb.Append(')');
631648
return sb;
632649
}
633650

@@ -648,9 +665,9 @@ public static StringBuilder EscapedString(StringBuilder sb, string str)
648665
else if (ch == '\"')
649666
sb.Append("\\\"");
650667
else if (ch == '\\')
651-
sb.Append("\\");
668+
sb.Append('\\');
652669
else if (ch < 0x20 || ch >= 0x7f)
653-
sb.AppendFormat("\\u{0:x4}", (int)ch);
670+
sb.AppendFormat(CultureInfo.InvariantCulture, "\\u{0:x4}", (int)ch);
654671
else
655672
sb.Append(ch);
656673
}
@@ -663,10 +680,10 @@ public static StringBuilder SigByteArrayToString(StringBuilder sb, byte[] sig)
663680
var length = sig.Length;
664681
for (var i = 0; i < length; i++)
665682
{
666-
sb.AppendFormat(i == 0 ? "SIG [" : " ");
683+
sb.Append(i == 0 ? "SIG [" : " ");
667684
sb.Append(Int8ToHex(sb, sig[i]));
668685
}
669-
sb.AppendFormat("]");
686+
sb.Append(']');
670687
return sb;
671688
}
672689
}

src/FastExpressionCompiler/TestTools.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
#nullable disable
2+
3+
using System;
24
using System.Linq;
35
using System.Text;
46
using System.Reflection;
@@ -19,18 +21,25 @@ namespace FastExpressionCompiler;
1921

2022
using FastExpressionCompiler.ILDecoder;
2123
using FastExpressionCompiler.ImTools;
24+
using System.Globalization;
2225
using System.Linq.Expressions;
2326
#endif
2427

28+
#pragma warning disable IDE0079 // Remove unnecessary suppression (like the ones below when they don't apply)
29+
#pragma warning disable IDE0250, IDE0251 // Readonly modifier
30+
2531
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
32+
#pragma warning disable CA1305 // Specify IFormatProvider
2633

2734
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is used for the testing purposes only.")]
2835
public static class TestTools
2936
{
30-
public static bool AllowPrintIL = false;
31-
public static bool AllowPrintCS = false;
32-
public static bool AllowPrintExpression = false;
33-
public static bool DisableAssertOpCodes = false;
37+
#pragma warning disable CA2211 // Non-constant fields should not be visible
38+
public static bool AllowPrintIL;
39+
public static bool AllowPrintCS;
40+
public static bool AllowPrintExpression;
41+
public static bool DisableAssertOpCodes;
42+
#pragma warning restore CA2211 // Non-constant fields should not be visible
3443

3544
static TestTools()
3645
{
@@ -567,7 +576,7 @@ public static bool StartsWith(string expected, string actual,
567576
string expectedName = "expected",
568577
[CallerArgumentExpression(nameof(actual))]
569578
string actualName = "actual") =>
570-
actual.StartsWith(expected) ? true : throw new AssertionException(
579+
actual.StartsWith(expected, StringComparison.Ordinal) ? true : throw new AssertionException(
571580
$"Expected string `StartsWith({expectedName}, {actualName})`, but found expected `{expected.ToCode()}` is not at start of `{actual.ToCode()}`");
572581
}
573582

@@ -613,6 +622,7 @@ public record struct TestStats(
613622
int FailureCount);
614623

615624
[Flags]
625+
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
616626
public enum TestFlags : byte
617627
{
618628
Default = 0,
@@ -628,13 +638,16 @@ class CallerMemberNameAttribute : Attribute { }
628638
class CallerLineNumberAttribute : Attribute { }
629639

630640
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
631-
class CallerArgumentExpression : Attribute
641+
class CallerArgumentExpressionAttribute : Attribute
632642
{
633-
public CallerArgumentExpression(string parameterName) { }
643+
#pragma warning disable IDE0060 // Remove unused parameter
644+
public CallerArgumentExpressionAttribute(string parameterName) { }
645+
#pragma warning restore IDE0060 // Remove unused parameter
634646
}
635647
#endif
636648

637649
/// <summary>Wrapper for the context per test method</summary>
650+
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
638651
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is used for the testing purposes only.")]
639652
public struct TestContext
640653
{
@@ -993,7 +1006,7 @@ public bool StartsWith(string expected, string actual,
9931006
string expectedName = "<expected>",
9941007
[CallerArgumentExpression(nameof(actual))]
9951008
string actualName = "<actual>") =>
996-
actual.StartsWith(expected) ? true : throw new AssertionException(
1009+
actual.StartsWith(expected, StringComparison.Ordinal) ? true : throw new AssertionException(
9971010
$"Expected string `StartsWith({expectedName}, {actualName})`, but found expected `{expected.ToCode()}` is not at start of `{actual.ToCode()}`");
9981011
}
9991012

0 commit comments

Comments
 (0)