Browse Source

printing of field named arguments in attributes.

pull/52/head
Artur Zgodziski 15 years ago
parent
commit
3609dd641a
  1. 17
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 13
      ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs

17
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -608,13 +608,22 @@ namespace Decompiler @@ -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);

13
ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs

@ -201,3 +201,16 @@ namespace NamedEnumPropertyParameter @@ -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
{
}
}

Loading…
Cancel
Save