Permalink
Browse files

Remove "Attribute" suffix and add support for attributes on type para…

…meters.
  • Loading branch information...
1 parent d1ccd69 commit ed118a1bd5906635ebfdf9a327434801ad0005fa @dgrunwald dgrunwald committed Mar 3, 2011
@@ -499,11 +499,16 @@ MethodDeclaration CreateMethod(MethodDefinition methodDef)
IEnumerable<TypeParameterDeclaration> MakeTypeParameters(IEnumerable<GenericParameter> genericParameters)
{
- return genericParameters.Select(
- gp => new TypeParameterDeclaration {
- Name = CleanName(gp.Name),
- Variance = gp.IsContravariant ? VarianceModifier.Contravariant : gp.IsCovariant ? VarianceModifier.Covariant : VarianceModifier.Invariant
- });
+ foreach (var gp in genericParameters) {
+ TypeParameterDeclaration tp = new TypeParameterDeclaration();
+ tp.Name = CleanName(gp.Name);
+ 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)
@@ -616,6 +621,11 @@ static void ConvertCustomAttributes(AstNode attributedNode, ICustomAttributeProv
var attribute = new ICSharpCode.NRefactory.CSharp.Attribute();
attribute.Type = ConvertType(customAttribute.AttributeType);
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) {
foreach (var parameter in customAttribute.ConstructorArguments) {
@@ -382,7 +382,7 @@ public class MyAttributeAttribute : Attribute
}
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
{
@@ -396,3 +396,14 @@ public class MyClass
}
}
}
+//$$ ClassAttributeOnTypeParameter
+namespace ClassAttributeOnTypeParameter
+{
+ [AttributeUsage(AttributeTargets.All)]
+ public class MyAttributeAttribute : Attribute
+ {
+ }
+ public class MyClass<[MyAttribute] T>
+ {
+ }
+}
@@ -14,7 +14,7 @@ public override object VisitAttribute(NRefactory.CSharp.Attribute attribute, obj
var section = (AttributeSection)attribute.Parent;
SimpleType type = attribute.Type as SimpleType;
if (section.AttributeTarget == AttributeTarget.Assembly &&
- (type.Identifier == "CompilationRelaxationsAttribute" || type.Identifier == "RuntimeCompatibilityAttribute"))
+ (type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility"))
{
attribute.Remove();
if (section.Attributes.Count == 0)
@@ -1135,7 +1135,9 @@ public object VisitAttributeSection(AttributeSection attributeSection, object da
}
WriteCommaSeparatedList(attributeSection.Attributes.SafeCast<Attribute, AstNode>());
WriteToken("]", AstNode.Roles.RBracket);
- if (!(attributeSection.Parent is ParameterDeclaration))
+ if (attributeSection.Parent is ParameterDeclaration || attributeSection.Parent is TypeParameterDeclaration)
+ Space();
+ else
NewLine();
return EndNode(attributeSection);
}

0 comments on commit ed118a1

Please sign in to comment.