Browse Source

attribute target: method return

pull/52/head
Artur Zgodziski 15 years ago
parent
commit
6b9c2b7462
  1. 5
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 16
      ICSharpCode.Decompiler/Tests/CustomAttributes/CustomAttributeSamples.cs

5
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -480,6 +480,7 @@ namespace Decompiler
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context); astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
} }
ConvertCustomAtributes(astMethod, methodDef); ConvertCustomAtributes(astMethod, methodDef);
ConvertCustomAtributes(astMethod, methodDef.MethodReturnType, AttributeTarget.Return);
return astMethod; return astMethod;
} }
@ -589,12 +590,12 @@ namespace Decompiler
} }
} }
static void ConvertCustomAtributes(AttributedNode attributedNode, ICustomAttributeProvider customAttributeProvider) static void ConvertCustomAtributes(AttributedNode attributedNode, ICustomAttributeProvider customAttributeProvider, AttributeTarget target = AttributeTarget.None)
{ {
if (customAttributeProvider.HasCustomAttributes) if (customAttributeProvider.HasCustomAttributes)
{ {
var section = new AttributeSection(); var section = new AttributeSection();
//section.AttributeTarget = target; section.AttributeTarget = target;
foreach (var customAttribute in customAttributeProvider.CustomAttributes) foreach (var customAttribute in customAttributeProvider.CustomAttributes)
{ {
ICSharpCode.NRefactory.CSharp.Attribute attribute = new ICSharpCode.NRefactory.CSharp.Attribute(); ICSharpCode.NRefactory.CSharp.Attribute attribute = new ICSharpCode.NRefactory.CSharp.Attribute();

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

@ -228,3 +228,19 @@ namespace NamedInitializerFieldEnum
{ {
} }
} }
//$$ TargetReturn
namespace TargetReturn
{
[AttributeUsage(AttributeTargets.All)]
public class MyAttributeAttribute : Attribute
{
}
public class MyClass
{
[return: MyAttribute]
public int MyMethod()
{
return 5;
}
}
}

Loading…
Cancel
Save