Browse Source

Fix five small analyzer warnings.

* ExtensionDeclaration.SymbolKind (CA1065) — was throwing
  NotImplementedException; return SymbolKind.TypeDefinition to match
  TypeDeclaration / DelegateDeclaration, since `extension` declarations
  are type-level.
* CustomAttribute.DecodeValue (CA2002) — replace `lock(this)` on the
  sealed-but-internal class with a private syncRoot field.
* PlainTextOutput (CA1001) — implement IDisposable; track an
  ownsWriter flag so we only dispose the underlying TextWriter when
  the parameterless constructor created its own StringWriter.
* DotNetCorePathFinder (CA1060) — move the libc realpath / free
  PInvokes into a private nested NativeMethods class.
* ILSpy.ReadyToRun (CA1016) — add [assembly: AssemblyVersion("1.0.0.0")]
  in Properties/AssemblyInfo.cs to match the BamlDecompiler plugin.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
pull/3732/head
Siegfried Pammer 2 weeks ago
parent
commit
317e33b3b8
  1. 2
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ExtensionDeclaration.cs
  2. 15
      ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs
  3. 11
      ICSharpCode.Decompiler/Output/PlainTextOutput.cs
  4. 3
      ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs
  5. 3
      ILSpy.ReadyToRun/Properties/AssemblyInfo.cs

2
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ExtensionDeclaration.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -24,7 +24,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
public readonly static TokenRole ExtensionKeywordRole = new TokenRole("extension");
public override SymbolKind SymbolKind => throw new System.NotImplementedException();
public override SymbolKind SymbolKind => SymbolKind.TypeDefinition;
public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole(Roles.TypeParameter); }

15
ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs

@ -318,7 +318,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -318,7 +318,7 @@ namespace ICSharpCode.Decompiler.Metadata
fixed (byte* input = bytes)
{
byte* output = GetRealPath(input, null);
byte* output = NativeMethods.GetRealPath(input, null);
if (output == null)
{
return null;
@ -330,15 +330,18 @@ namespace ICSharpCode.Decompiler.Metadata @@ -330,15 +330,18 @@ namespace ICSharpCode.Decompiler.Metadata
}
byte[] result = new byte[len];
Marshal.Copy((IntPtr)output, result, 0, result.Length);
Free(output);
NativeMethods.Free(output);
return encoding.GetString(result);
}
}
[DllImport("libc", EntryPoint = "realpath")]
static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath);
static class NativeMethods
{
[DllImport("libc", EntryPoint = "realpath")]
internal static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath);
[DllImport("libc", EntryPoint = "free")]
static extern unsafe void Free(void* ptr);
[DllImport("libc", EntryPoint = "free")]
internal static extern unsafe void Free(void* ptr);
}
}
}

11
ICSharpCode.Decompiler/Output/PlainTextOutput.cs

@ -28,9 +28,10 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -28,9 +28,10 @@ using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler
{
public sealed class PlainTextOutput : ITextOutput
public sealed class PlainTextOutput : ITextOutput, IDisposable
{
readonly TextWriter writer;
readonly bool ownsWriter;
int indent;
bool needsIndent;
@ -44,11 +45,19 @@ namespace ICSharpCode.Decompiler @@ -44,11 +45,19 @@ namespace ICSharpCode.Decompiler
if (writer == null)
throw new ArgumentNullException(nameof(writer));
this.writer = writer;
this.ownsWriter = false;
}
public PlainTextOutput()
{
this.writer = new StringWriter();
this.ownsWriter = true;
}
public void Dispose()
{
if (ownsWriter)
writer.Dispose();
}
public TextLocation Location {

3
ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs

@ -40,6 +40,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -40,6 +40,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
CustomAttributeValue<IType> value;
bool valueDecoded;
bool hasDecodeErrors;
readonly object syncRoot = new object();
internal CustomAttribute(MetadataModule module, IMethod attrCtor, CustomAttributeHandle handle)
{
@ -76,7 +77,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -76,7 +77,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
void DecodeValue()
{
lock (this)
lock (syncRoot)
{
try
{

3
ILSpy.ReadyToRun/Properties/AssemblyInfo.cs

@ -8,7 +8,8 @@ using System.Runtime.Versioning; @@ -8,7 +8,8 @@ using System.Runtime.Versioning;
[assembly: TargetPlatform("Windows10.0")]
[assembly: SupportedOSPlatform("Windows7.0")]
// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyVersion("1.0.0.0")]

Loading…
Cancel
Save