From 36a432940b392eb9efa1795ee4bef3578c6624cd Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 17 Aug 2020 18:06:35 +0200 Subject: [PATCH] Fix #2100: 'value'-named auto property could not be recognized correctly. --- .../TestCases/Pretty/AutoProperties.cs | 5 +++++ ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AutoProperties.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AutoProperties.cs index 0632affe9..8b0f4e15a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AutoProperties.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AutoProperties.cs @@ -23,6 +23,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty set; } = 4; + public string value { + get; + set; + } + [Obsolete("Property")] [field: Obsolete("Field")] public int PropertyWithAttributeOnBackingField { diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 09bbb7c19..1eeb1d0a6 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -244,7 +244,10 @@ namespace ICSharpCode.Decompiler.CSharp // in PatternStatementTransform, then we have to do the "requires qualifier"-check based on the property instead of the field. // It is easier to solve this special case here than in PatternStatementTransform, because here we perform all resolver checks. // It feels a bit hacky, though. - if (settings.AutomaticProperties && PatternStatementTransform.IsBackingFieldOfAutomaticProperty(field, out var property)) { + if (settings.AutomaticProperties + && PatternStatementTransform.IsBackingFieldOfAutomaticProperty(field, out var property) + && !(this.decompilationContext.CurrentMember == property)) + { requireTarget = RequiresQualifier(property, target); } else { requireTarget = RequiresQualifier(field, target);