mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
C# has no syntax for named properties with parameters, so the expected output declares the accessors as ordinary methods, keeps the property-level attributes under the inert 'property:' attribute target (ignored by csc with CS0657), and consumes the properties through direct accessor calls, which Roslyn permits exactly for properties whose shape C# cannot bind. Red against the current decompiler, which emits a parameterless property whose body references the vanished parameters. Assisted-by: Claude:claude-fable-5:Claude Codepull/3925/head
4 changed files with 128 additions and 0 deletions
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
#pragma warning disable 657
|
||||
using System; |
||||
|
||||
public interface IParameterized |
||||
{ |
||||
// C# has no syntax for parameterized properties; the accessors of
|
||||
// property 'IndexedValue' are emitted as ordinary methods.
|
||||
int get_IndexedValue(int index); |
||||
void set_IndexedValue(int index, int Value); |
||||
} |
||||
|
||||
public class ParameterizedProperties : IParameterized |
||||
{ |
||||
private int _field; |
||||
|
||||
// C# has no syntax for parameterized properties; the accessors of
|
||||
// property 'SharedProp' are emitted as ordinary methods.
|
||||
public static int get_SharedProp(int index) |
||||
{ |
||||
return index; |
||||
} |
||||
|
||||
public static void set_SharedProp(int index, int value) |
||||
{ |
||||
} |
||||
|
||||
// C# has no syntax for parameterized properties; the accessors of
|
||||
// property 'IndexedValue' are emitted as ordinary methods.
|
||||
public int get_IndexedValue(int index) |
||||
{ |
||||
return _field; |
||||
} |
||||
|
||||
public void set_IndexedValue(int index, int value) |
||||
{ |
||||
_field = value; |
||||
} |
||||
|
||||
// C# has no syntax for parameterized properties; the accessors of
|
||||
// property 'ReadOnlyProp' are emitted as ordinary methods.
|
||||
public int get_ReadOnlyProp(int index) |
||||
{ |
||||
return index; |
||||
} |
||||
|
||||
// C# has no syntax for parameterized properties; the accessors of
|
||||
// property 'Attributed' are emitted as ordinary methods. The property's
|
||||
// attributes are kept below under the inert 'property:' target (CS0657).
|
||||
[property: Obsolete("read-write parameterized property")] |
||||
public int get_Attributed(int index) |
||||
{ |
||||
return index; |
||||
} |
||||
|
||||
public void set_Attributed(int index, int value) |
||||
{ |
||||
} |
||||
|
||||
public void Use() |
||||
{ |
||||
ParameterizedProperties.set_SharedProp(1, 2); |
||||
_field = ParameterizedProperties.get_SharedProp(3); |
||||
this.set_IndexedValue(4, 5); |
||||
_field = this.get_IndexedValue(6); |
||||
((IParameterized)this).set_IndexedValue(7, 8); |
||||
_field = ((IParameterized)this).get_IndexedValue(9); |
||||
} |
||||
} |
||||
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
Imports System |
||||
|
||||
Public Interface IParameterized |
||||
Property IndexedValue(index As Integer) As Integer |
||||
End Interface |
||||
|
||||
Public Class ParameterizedProperties |
||||
Implements IParameterized |
||||
|
||||
Private _field As Integer |
||||
|
||||
Public Shared Property SharedProp(index As Integer) As Integer |
||||
Get |
||||
Return index |
||||
End Get |
||||
Set(value As Integer) |
||||
End Set |
||||
End Property |
||||
|
||||
Public Property IndexedValue(index As Integer) As Integer Implements IParameterized.IndexedValue |
||||
Get |
||||
Return _field |
||||
End Get |
||||
Set(value As Integer) |
||||
_field = value |
||||
End Set |
||||
End Property |
||||
|
||||
Public ReadOnly Property ReadOnlyProp(index As Integer) As Integer |
||||
Get |
||||
Return index |
||||
End Get |
||||
End Property |
||||
|
||||
<Obsolete("read-write parameterized property")> |
||||
Public Property Attributed(index As Integer) As Integer |
||||
Get |
||||
Return index |
||||
End Get |
||||
Set(value As Integer) |
||||
End Set |
||||
End Property |
||||
|
||||
Public Sub Use() |
||||
SharedProp(1) = 2 |
||||
_field = SharedProp(3) |
||||
IndexedValue(4) = 5 |
||||
_field = IndexedValue(6) |
||||
Dim p As IParameterized = Me |
||||
p.IndexedValue(7) = 8 |
||||
_field = p.IndexedValue(9) |
||||
End Sub |
||||
End Class |
||||
Loading…
Reference in new issue