Browse Source

Remove "Attribute" suffix and add support for attributes on type parameters.

pull/70/head
Daniel Grunwald 16 years ago
parent
commit
ed118a1bd5
  1. 20
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 13
      ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs
  3. 2
      ICSharpCode.Decompiler/Tests/Helpers/RemoveCompilerAttribute.cs
  4. 4
      NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

20
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -499,11 +499,16 @@ namespace Decompiler
IEnumerable<TypeParameterDeclaration> MakeTypeParameters(IEnumerable<GenericParameter> genericParameters) IEnumerable<TypeParameterDeclaration> MakeTypeParameters(IEnumerable<GenericParameter> genericParameters)
{ {
return genericParameters.Select( foreach (var gp in genericParameters) {
gp => new TypeParameterDeclaration { TypeParameterDeclaration tp = new TypeParameterDeclaration();
Name = CleanName(gp.Name), tp.Name = CleanName(gp.Name);
Variance = gp.IsContravariant ? VarianceModifier.Contravariant : gp.IsCovariant ? VarianceModifier.Covariant : VarianceModifier.Invariant if (gp.IsContravariant)
}); tp.Variance = VarianceModifier.Contravariant;
else if (gp.IsCovariant)
tp.Variance = VarianceModifier.Covariant;
ConvertCustomAttributes(tp, gp);
yield return tp;
}
} }
IEnumerable<Constraint> MakeConstraints(IEnumerable<GenericParameter> genericParameters) IEnumerable<Constraint> MakeConstraints(IEnumerable<GenericParameter> genericParameters)
@ -616,6 +621,11 @@ namespace Decompiler
var attribute = new ICSharpCode.NRefactory.CSharp.Attribute(); var attribute = new ICSharpCode.NRefactory.CSharp.Attribute();
attribute.Type = ConvertType(customAttribute.AttributeType); attribute.Type = ConvertType(customAttribute.AttributeType);
attributes.Add(attribute); attributes.Add(attribute);
SimpleType st = attribute.Type as SimpleType;
if (st != null && st.Identifier.EndsWith("Attribute", StringComparison.Ordinal)) {
st.Identifier = st.Identifier.Substring(0, st.Identifier.Length - "Attribute".Length);
}
if(customAttribute.HasConstructorArguments) { if(customAttribute.HasConstructorArguments) {
foreach (var parameter in customAttribute.ConstructorArguments) { foreach (var parameter in customAttribute.ConstructorArguments) {

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

@ -382,7 +382,7 @@ namespace TargetPropertyIndexSetMultiParam
} }
public class MyClass public class MyClass
{ {
public string this[[MyAttribute(Field = 2)]int index1, [MyAttribute(Field = 3)]int index2] public string this[[MyAttribute(Field = 2)] int index1, [MyAttribute(Field = 3)] int index2]
{ {
get get
{ {
@ -396,3 +396,14 @@ namespace TargetPropertyIndexSetMultiParam
} }
} }
} }
//$$ ClassAttributeOnTypeParameter
namespace ClassAttributeOnTypeParameter
{
[AttributeUsage(AttributeTargets.All)]
public class MyAttributeAttribute : Attribute
{
}
public class MyClass<[MyAttribute] T>
{
}
}

2
ICSharpCode.Decompiler/Tests/Helpers/RemoveCompilerAttribute.cs

@ -14,7 +14,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
var section = (AttributeSection)attribute.Parent; var section = (AttributeSection)attribute.Parent;
SimpleType type = attribute.Type as SimpleType; SimpleType type = attribute.Type as SimpleType;
if (section.AttributeTarget == AttributeTarget.Assembly && if (section.AttributeTarget == AttributeTarget.Assembly &&
(type.Identifier == "CompilationRelaxationsAttribute" || type.Identifier == "RuntimeCompatibilityAttribute")) (type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility"))
{ {
attribute.Remove(); attribute.Remove();
if (section.Attributes.Count == 0) if (section.Attributes.Count == 0)

4
NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -1135,7 +1135,9 @@ namespace ICSharpCode.NRefactory.CSharp
} }
WriteCommaSeparatedList(attributeSection.Attributes.SafeCast<Attribute, AstNode>()); WriteCommaSeparatedList(attributeSection.Attributes.SafeCast<Attribute, AstNode>());
WriteToken("]", AstNode.Roles.RBracket); WriteToken("]", AstNode.Roles.RBracket);
if (!(attributeSection.Parent is ParameterDeclaration)) if (attributeSection.Parent is ParameterDeclaration || attributeSection.Parent is TypeParameterDeclaration)
Space();
else
NewLine(); NewLine();
return EndNode(attributeSection); return EndNode(attributeSection);
} }

Loading…
Cancel
Save