Skip to content

Commit f8c8649

Browse files
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 ctor created its own StringWriter. * DotNetCorePathFinder (CA1060) — move the libc realpath/free PInvokes into a private nested NativeMethods class. * ILSpy.ReadyToRun (CA1016) — add [assembly: AssemblyVersion] in Properties/AssemblyInfo.cs to match the BamlDecompiler plugin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ec5ea3a commit f8c8649

5 files changed

Lines changed: 24 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ExtensionDeclaration : EntityDeclaration
2424
{
2525
public readonly static TokenRole ExtensionKeywordRole = new TokenRole("extension");
2626

27-
public override SymbolKind SymbolKind => throw new System.NotImplementedException();
27+
public override SymbolKind SymbolKind => SymbolKind.TypeDefinition;
2828

2929
public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
3030
get { return GetChildrenByRole(Roles.TypeParameter); }

ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static unsafe string GetRealPath(string path, Encoding encoding)
318318
fixed (byte* input = bytes)
319319
{
320320

321-
byte* output = GetRealPath(input, null);
321+
byte* output = NativeMethods.GetRealPath(input, null);
322322
if (output == null)
323323
{
324324
return null;
@@ -330,15 +330,18 @@ static unsafe string GetRealPath(string path, Encoding encoding)
330330
}
331331
byte[] result = new byte[len];
332332
Marshal.Copy((IntPtr)output, result, 0, result.Length);
333-
Free(output);
333+
NativeMethods.Free(output);
334334
return encoding.GetString(result);
335335
}
336336
}
337337

338-
[DllImport("libc", EntryPoint = "realpath")]
339-
static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath);
338+
static class NativeMethods
339+
{
340+
[DllImport("libc", EntryPoint = "realpath")]
341+
internal static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath);
340342

341-
[DllImport("libc", EntryPoint = "free")]
342-
static extern unsafe void Free(void* ptr);
343+
[DllImport("libc", EntryPoint = "free")]
344+
internal static extern unsafe void Free(void* ptr);
345+
}
343346
}
344347
}

ICSharpCode.Decompiler/Output/PlainTextOutput.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828

2929
namespace ICSharpCode.Decompiler
3030
{
31-
public sealed class PlainTextOutput : ITextOutput
31+
public sealed class PlainTextOutput : ITextOutput, IDisposable
3232
{
3333
readonly TextWriter writer;
34+
readonly bool ownsWriter;
3435
int indent;
3536
bool needsIndent;
3637

@@ -44,11 +45,19 @@ public PlainTextOutput(TextWriter writer)
4445
if (writer == null)
4546
throw new ArgumentNullException(nameof(writer));
4647
this.writer = writer;
48+
this.ownsWriter = false;
4749
}
4850

4951
public PlainTextOutput()
5052
{
5153
this.writer = new StringWriter();
54+
this.ownsWriter = true;
55+
}
56+
57+
public void Dispose()
58+
{
59+
if (ownsWriter)
60+
writer.Dispose();
5261
}
5362

5463
public TextLocation Location {

ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sealed class CustomAttribute : IAttribute
4040
CustomAttributeValue<IType> value;
4141
bool valueDecoded;
4242
bool hasDecodeErrors;
43+
readonly object syncRoot = new object();
4344

4445
internal CustomAttribute(MetadataModule module, IMethod attrCtor, CustomAttributeHandle handle)
4546
{
@@ -76,7 +77,7 @@ public bool HasDecodeErrors {
7677

7778
void DecodeValue()
7879
{
79-
lock (this)
80+
lock (syncRoot)
8081
{
8182
try
8283
{

ILSpy.ReadyToRun/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[assembly: TargetPlatform("Windows10.0")]
99
[assembly: SupportedOSPlatform("Windows7.0")]
1010

11-
// General Information about an assembly is controlled through the following
11+
// General Information about an assembly is controlled through the following
1212
// set of attributes. Change these attribute values to modify the information
1313
// associated with an assembly.
1414
[assembly: NeutralResourcesLanguage("en-US")]
15+
[assembly: AssemblyVersion("1.0.0.0")]

0 commit comments

Comments
 (0)