|
|
|
@ -22,10 +22,8 @@ using System.Diagnostics;
@@ -22,10 +22,8 @@ using System.Diagnostics;
|
|
|
|
|
using System.Linq; |
|
|
|
|
using ICSharpCode.Decompiler.CSharp.Syntax; |
|
|
|
|
using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; |
|
|
|
|
using ICSharpCode.Decompiler.CSharp.TypeSystem; |
|
|
|
|
using ICSharpCode.Decompiler.TypeSystem; |
|
|
|
|
using ICSharpCode.Decompiler.Semantics; |
|
|
|
|
using Mono.Cecil; |
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.Decompiler.CSharp.Transforms |
|
|
|
|
{ |
|
|
|
@ -484,31 +482,28 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -484,31 +482,28 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
PropertyDeclaration TransformAutomaticProperties(PropertyDeclaration property) |
|
|
|
|
PropertyDeclaration TransformAutomaticProperties(PropertyDeclaration propertyDeclaration) |
|
|
|
|
{ |
|
|
|
|
PropertyDefinition cecilProperty = context.TypeSystem.GetCecil(property.GetSymbol() as IProperty) as PropertyDefinition; |
|
|
|
|
if (cecilProperty == null || cecilProperty.GetMethod == null) |
|
|
|
|
IProperty property = propertyDeclaration.GetSymbol() as IProperty; |
|
|
|
|
if (!property.CanGet || (!property.Getter.IsCompilerGenerated() && (property.Setter?.IsCompilerGenerated() == false))) |
|
|
|
|
return null; |
|
|
|
|
if (!cecilProperty.GetMethod.IsCompilerGenerated() && (cecilProperty.SetMethod?.IsCompilerGenerated() == false)) |
|
|
|
|
return null; |
|
|
|
|
IField fieldInfo = null; |
|
|
|
|
Match m = automaticPropertyPattern.Match(property); |
|
|
|
|
IField field = null; |
|
|
|
|
Match m = automaticPropertyPattern.Match(propertyDeclaration); |
|
|
|
|
if (m.Success) { |
|
|
|
|
fieldInfo = m.Get<AstNode>("fieldReference").Single().GetSymbol() as IField; |
|
|
|
|
field = m.Get<AstNode>("fieldReference").Single().GetSymbol() as IField; |
|
|
|
|
} else { |
|
|
|
|
Match m2 = automaticReadonlyPropertyPattern.Match(property); |
|
|
|
|
Match m2 = automaticReadonlyPropertyPattern.Match(propertyDeclaration); |
|
|
|
|
if (m2.Success) { |
|
|
|
|
fieldInfo = m2.Get<AstNode>("fieldReference").Single().GetSymbol() as IField; |
|
|
|
|
field = m2.Get<AstNode>("fieldReference").Single().GetSymbol() as IField; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (fieldInfo == null) |
|
|
|
|
if (field == null) |
|
|
|
|
return null; |
|
|
|
|
FieldDefinition field = context.TypeSystem.GetCecil(fieldInfo) as FieldDefinition; |
|
|
|
|
if (field.IsCompilerGenerated() && field.DeclaringType == cecilProperty.DeclaringType) { |
|
|
|
|
RemoveCompilerGeneratedAttribute(property.Getter.Attributes); |
|
|
|
|
RemoveCompilerGeneratedAttribute(property.Setter.Attributes); |
|
|
|
|
property.Getter.Body = null; |
|
|
|
|
property.Setter.Body = null; |
|
|
|
|
if (field.IsCompilerGenerated() && field.DeclaringTypeDefinition == property.DeclaringTypeDefinition) { |
|
|
|
|
RemoveCompilerGeneratedAttribute(propertyDeclaration.Getter.Attributes); |
|
|
|
|
RemoveCompilerGeneratedAttribute(propertyDeclaration.Setter.Attributes); |
|
|
|
|
propertyDeclaration.Getter.Body = null; |
|
|
|
|
propertyDeclaration.Setter.Body = null; |
|
|
|
|
} |
|
|
|
|
// Since the property instance is not changed, we can continue in the visitor as usual, so return null
|
|
|
|
|
return null; |
|
|
|
|