Browse Source

Convert [ParamArray] and [Extension] to 'params'/'this' modifiers.

pull/100/head
Daniel Grunwald 15 years ago
parent
commit
2228f29330
  1. 25
      ICSharpCode.Decompiler/Ast/AstBuilder.cs

25
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -602,6 +602,13 @@ namespace ICSharpCode.Decompiler.Ast
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context); astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
} }
ConvertAttributes(astMethod, methodDef); ConvertAttributes(astMethod, methodDef);
if (methodDef.HasCustomAttributes && astMethod.Parameters.Count > 0) {
foreach (CustomAttribute ca in methodDef.CustomAttributes) {
if (ca.AttributeType.Name == "ExtensionAttribute" && ca.AttributeType.Namespace == "System.Runtime.CompilerServices") {
astMethod.Parameters.First().ParameterModifier = ParameterModifier.This;
}
}
}
return astMethod; return astMethod;
} }
@ -792,7 +799,12 @@ namespace ICSharpCode.Decompiler.Ast
if (paramDef.ParameterType is ByReferenceType) { if (paramDef.ParameterType is ByReferenceType) {
astParam.ParameterModifier = (!paramDef.IsIn && paramDef.IsOut) ? ParameterModifier.Out : ParameterModifier.Ref; astParam.ParameterModifier = (!paramDef.IsIn && paramDef.IsOut) ? ParameterModifier.Out : ParameterModifier.Ref;
} }
// TODO: params, this if (paramDef.HasCustomAttributes) {
foreach (CustomAttribute ca in paramDef.CustomAttributes) {
if (ca.AttributeType.Name == "ParamArrayAttribute" && ca.AttributeType.Namespace == "System")
astParam.ParameterModifier = ParameterModifier.Params;
}
}
ConvertCustomAttributes(astParam, paramDef); ConvertCustomAttributes(astParam, paramDef);
ModuleDefinition module = ((MethodDefinition)paramDef.Method).Module; ModuleDefinition module = ((MethodDefinition)paramDef.Method).Module;
@ -1019,6 +1031,15 @@ namespace ICSharpCode.Decompiler.Ast
if (customAttributeProvider.HasCustomAttributes) { if (customAttributeProvider.HasCustomAttributes) {
var attributes = new List<ICSharpCode.NRefactory.CSharp.Attribute>(); var attributes = new List<ICSharpCode.NRefactory.CSharp.Attribute>();
foreach (var customAttribute in customAttributeProvider.CustomAttributes) { foreach (var customAttribute in customAttributeProvider.CustomAttributes) {
if (customAttribute.AttributeType.Name == "ExtensionAttribute" && customAttribute.AttributeType.Namespace == "System.Runtime.CompilerServices") {
// don't show the ExtensionAttribute (it's converted to the 'this' modifier)
continue;
}
if (customAttribute.AttributeType.Name == "ParamArrayAttribute" && customAttribute.AttributeType.Namespace == "System") {
// don't show the ParamArrayAttribute (it's converted to the 'params' modifier)
continue;
}
var attribute = new ICSharpCode.NRefactory.CSharp.Attribute(); var attribute = new ICSharpCode.NRefactory.CSharp.Attribute();
attribute.AddAnnotation(customAttribute); attribute.AddAnnotation(customAttribute);
attribute.Type = ConvertType(customAttribute.AttributeType); attribute.Type = ConvertType(customAttribute.AttributeType);
@ -1064,7 +1085,7 @@ namespace ICSharpCode.Decompiler.Ast
section.Attributes.Add(attribute); section.Attributes.Add(attribute);
attributedNode.AddChild(section, AttributedNode.AttributeRole); attributedNode.AddChild(section, AttributedNode.AttributeRole);
} }
} else { } else if (attributes.Count > 0) {
// use single section for all attributes // use single section for all attributes
var section = new AttributeSection(); var section = new AttributeSection();
section.AttributeTarget = target; section.AttributeTarget = target;

Loading…
Cancel
Save