Browse Source

Add support for `in parameters` in primary ctor of records

pull/2476/head
SilverFox 4 years ago
parent
commit
1367e7ba95
  1. 1
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Records.cs
  2. 10
      ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

1
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Records.cs

@ -45,6 +45,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -45,6 +45,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public double C = 1.0;
public string D = A + B;
}
public record PrimaryCtorWithInParameter(in int A, in string B);
public record PrimaryCtorWithProperty(int A, string B)
{
public double C { get; init; } = 1.0;

10
ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

@ -196,6 +196,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -196,6 +196,11 @@ namespace ICSharpCode.Decompiler.CSharp
return false;
if (!target.MatchLdThis())
return false;
if (method.Parameters[i].IsIn)
{
if (!valueInst.MatchLdObj(out valueInst, out _))
return false;
}
if (!valueInst.MatchLdLoc(out var value))
return false;
if (!(value.Kind == VariableKind.Parameter && value.Index == i))
@ -984,7 +989,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -984,7 +989,10 @@ namespace ICSharpCode.Decompiler.CSharp
if (!deconstruct.IsOut)
return false;
if (!ctor.Type.Equals(((ByReferenceType)deconstruct.Type).ElementType))
IType ctorType = ctor.Type;
if (ctor.IsIn)
ctorType = ((ByReferenceType)ctorType).ElementType;
if (!ctorType.Equals(((ByReferenceType)deconstruct.Type).ElementType))
return false;
if (ctor.Name != deconstruct.Name)

Loading…
Cancel
Save