diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index 94473dba2..8be1173f0 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -608,13 +608,22 @@ namespace Decompiler } if (customAttribute.HasProperties) - foreach (var property in customAttribute.Properties) + foreach (var propertyNamedArg in customAttribute.Properties) { - var propertyReference = customAttribute.AttributeType.Resolve().Properties.First(pr => pr.Name == property.Name); - var propertyName = new IdentifierExpression(property.Name).WithAnnotation(propertyReference); - var argumentValue = ConvertArgumentValue(property.Argument); + var propertyReference = customAttribute.AttributeType.Resolve().Properties.First(pr => pr.Name == propertyNamedArg.Name); + var propertyName = new IdentifierExpression(propertyNamedArg.Name).WithAnnotation(propertyReference); + var argumentValue = ConvertArgumentValue(propertyNamedArg.Argument); attribute.Arguments.Add(new AssignmentExpression(propertyName, argumentValue)); } + + if (customAttribute.HasFields) + foreach (var fieldNamedArg in customAttribute.Fields) + { + var fieldReference = customAttribute.AttributeType.Resolve().Fields.First(f => f.Name == fieldNamedArg.Name); + var fieldName = new IdentifierExpression(fieldNamedArg.Name).WithAnnotation(fieldReference); + var argumentValue = ConvertArgumentValue(fieldNamedArg.Argument); + attribute.Arguments.Add(new AssignmentExpression(fieldName, argumentValue)); + } } attributedNode.Attributes.Add(section); diff --git a/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs b/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs index af74a2a6a..1d91f1fe0 100644 --- a/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs +++ b/ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs @@ -201,3 +201,16 @@ namespace NamedEnumPropertyParameter { } } +//$$ NamedEnumFieldParameter +namespace NamedEnumFieldParameter +{ + [AttributeUsage(AttributeTargets.All)] + public class MyAttributeAttribute : Attribute + { + public AttributeTargets Field; + } + [MyAttribute(Field = (AttributeTargets.Class | AttributeTargets.Method))] + public class MyClass + { + } +}