Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ private static string ReplacePrivImplDetails(string il)
"System.Linq.Queryable.dll",
"System.IO.FileSystem.Watcher.dll",
"System.Memory.dll",
"System.ObjectModel.dll",
"System.Threading.dll",
"System.Threading.Thread.dll",
"System.Runtime.dll",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@
<None Include="TestCases\ILPretty\Unsafe.cs" />
<Compile Remove="TestCases\ILPretty\WeirdEnums.cs" />
<None Include="TestCases\ILPretty\WeirdEnums.cs" />
<Compile Remove="TestCases\Pretty\FieldKeyword.cs" />
<None Include="TestCases\Pretty\FieldKeyword.cs" />
<Compile Remove="TestCases\Pretty\IndexRangeTest.cs" />
<None Include="TestCases\Pretty\IndexRangeTest.cs" />
<Compile Remove="TestCases\Pretty\MetadataAttributes.cs" />
Expand All @@ -248,6 +250,8 @@
<None Include="TestCases\Ugly\NoDecimalConstants.Expected.cs" />
<Compile Remove="TestCases\Ugly\NoExtensionMethods.Expected.cs" />
<None Include="TestCases\Ugly\NoExtensionMethods.Expected.cs" />
<Compile Remove="TestCases\Ugly\NoFieldKeyword.Expected.cs" />
<None Include="TestCases\Ugly\NoFieldKeyword.Expected.cs" />
<Compile Remove="TestCases\Ugly\NoForEachStatement.Expected.cs" />
<None Include="TestCases\Ugly\NoForEachStatement.Expected.cs" />
<Compile Remove="TestCases\Ugly\NoLocalFunctions.Expected.cs" />
Expand Down
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ public async Task ExtensionEverything([ValueSource(nameof(roslyn5OrNewerOptions)
await RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview | CompilerOptions.NullableEnable);
}

[Test]
public async Task FieldKeyword([ValueSource(nameof(roslyn5OrNewerOptions))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions | CompilerOptions.NullableEnable);
}

[Test]
public async Task NullPropagation([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions)
{
Expand Down
246 changes: 246 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/FieldKeyword.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
using System;
using System.ComponentModel;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal class FieldKeyword
{
public class BaseVirtual
{
public virtual int P {
get {
return field;
}
set {
field = value + 1;
}
}
}

public class DerivedVirtual : BaseVirtual
{
public override int P {
get {
return field * 2;
}
set {
field = value - 1;
}
}
}

public class Generic<T> where T : class
{
public T? Item {
get {
return field;
}
set {
if (value != null)
{
field = value;
}
}
}

public T Lazy => field ?? (field = Activator.CreateInstance<T>());
}

public class Notify : INotifyPropertyChanged
{
public string Name {
get {
return field;
}
set {
if (field != value)
{
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
}
}
} = "";

public event PropertyChangedEventHandler? PropertyChanged;
}

public struct StructProperties
{
public int Value {
get {
return field;
}
set {
field = value & 0xFF;
}
}

public readonly int Doubled => field * 2;

public StructProperties(int doubled)
{
Doubled = doubled;
}
}

public class RealFieldName
{
private int field;

public int PlusOne => this.field + 1;

public void Reset()
{
field = 0;
}
}

// 0.00m and -0.0 compare equal to their defaults but are observably different, so
// neither initializer may be dropped as a redundant default.
public struct PreciseDefaults
{
public decimal Scale {
get {
return field;
}
set {
field = value;
}
} = 0.00m;

public double Sign {
get {
return field;
}
set {
field = value;
}
} = -0.0;

public PreciseDefaults()
{
}
}

public Func<int> Capture {
get {
return () => (field != null) ? 1 : 0;
}
set;
}

public int GetOnly {
get {
if (field == 0)
{
field = 42;
}
return field;
}
}

public string InitChecked {
get;
init {
field = value.Trim();
}
} = "";

public int LazyGet {
get {
if (field == 0)
{
field = ComputeDefault();
}
return field;
}
set;
}

public string NullResilient => field ?? (field = CreateDefault());

public string? OptionalText {
get {
return field;
}
set {
field = value ?? string.Empty;
}
}

public int SetOnly {
set {
field = value * 2;
}
}

public int SetterValidated {
get;
set {
if (value < 0)
{
throw new ArgumentOutOfRangeException("value");
}
field = value;
}
}

public static int StaticCounter {
get {
return field;
}
set {
field = Math.Max(field, value);
}
}

public static Func<int> StaticFuncProperty {
get {
return () => (field == null) ? 1 : 2;
}
set;
}

public int TrivialGet => field;

public int ViaLocalFunction {
get {
return Twice();
int Twice()
{
return field * 2;
}
}
set;
}

[field: NonSerialized]
public int WithFieldAttribute {
get {
return field;
}
set {
field = value & 0xF;
}
}

public int WithInit {
get {
return field;
}
set {
field = value + 1;
}
} = 5;

private static int ComputeDefault()
{
return 7;
}

private static string CreateDefault()
{
return "x";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
#if !OPT
using System.Diagnostics;
#endif
using System.Runtime.CompilerServices;

namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly;

internal class GenericHolder<T> where T : class
{
[CompilerGenerated]
#if !OPT
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
private T Value__BackingField;

public T Value {
get {
return Value__BackingField;
}
set {
if (value != null)
{
Value__BackingField = value;
}
}
}
}
internal class NoFieldKeyword
{
[CompilerGenerated]
#if !OPT
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
private int Clamped__BackingField;

[CompilerGenerated]
#if !OPT
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
private int WithInitializer__BackingField = 5;

public int Clamped {
get {
return Clamped__BackingField;
}
set {
Clamped__BackingField = Math.Max(0, value);
}
}

public int WithInitializer {
get {
return WithInitializer__BackingField;
}
set {
WithInitializer__BackingField = value + 1;
}
}
}
Loading
Loading