Browse Source

partial support for named arguments in attributes.

pull/52/head
Artur Zgodziski 15 years ago
parent
commit
09177affc1
  1. 9
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 10
      ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs

9
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -600,6 +600,7 @@ namespace Decompiler @@ -600,6 +600,7 @@ namespace Decompiler
attribute.Type = ConvertType(customAttribute.AttributeType);
section.Attributes.Add(attribute);
if(customAttribute.HasConstructorArguments)
foreach (var parameter in customAttribute.ConstructorArguments)
{
var isEnum = parameter.Type.IsValueType && !parameter.Type.IsPrimitive;
@ -615,6 +616,14 @@ namespace Decompiler @@ -615,6 +616,14 @@ namespace Decompiler
attribute.Arguments.Add(parameterValue);
}
if (customAttribute.HasProperties)
foreach (var property in customAttribute.Properties)
{
var propertyReference = customAttribute.AttributeType.Resolve().Properties.First(pr => pr.Name == property.Name);
var propertyName = new IdentifierExpression(property.Name).WithAnnotation(propertyReference);
var propertyArgument = new PrimitiveExpression(property.Argument.Value);
attribute.Arguments.Add(new AssignmentExpression(propertyName, propertyArgument));
}
}
attributedNode.Attributes.Add(section);

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

@ -11,7 +11,7 @@ namespace ParameterLessAttributeUsage @@ -11,7 +11,7 @@ namespace ParameterLessAttributeUsage
[Flags]
public enum EnumWithFlagsAttribute
{
None
None = 0
}
}
//$$ AttributeWithEnumArgument
@ -79,3 +79,11 @@ namespace AttributeAppliedToMethod @@ -79,3 +79,11 @@ namespace AttributeAppliedToMethod
}
}
}
//$$ NamedParameter
namespace NamedParameter
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class MyAttributeAttribute : Attribute
{
}
}

Loading…
Cancel
Save