Skip to content

Commit

Permalink
IkvmLoader: fix attributes on type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Jun 5, 2015
1 parent bca1946 commit 86856e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ICSharpCode.NRefactory.IKVM/IkvmLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ void AddAttributes(PropertyInfo propertyDefinition, IUnresolvedEntity targetEnti
AddCustomAttributes(propertyDefinition.CustomAttributes, targetEntity.Attributes);
}
#endregion

#region Type Parameter Attributes
void AddAttributes(IKVM.Reflection.Type genericParameter, IUnresolvedTypeParameter targetTP)
{
AddCustomAttributes(genericParameter.CustomAttributes, targetTP.Attributes);
}
#endregion

#region MarshalAsAttribute (ConvertMarshalInfo)
static readonly ITypeReference marshalAsAttributeTypeRef = typeof(MarshalAsAttribute).ToTypeReference();
Expand Down Expand Up @@ -842,6 +849,7 @@ void InitTypeParameterConstraints(IKVM.Reflection.Type typeDefinition, IList<IUn
for (int i = 0; i < typeParameters.Count; i++) {
var tp = (DefaultUnresolvedTypeParameter)typeParameters[i];
AddConstraints(tp, args[i]);
AddAttributes(args[i], tp);
tp.ApplyInterningProvider(interningProvider);
}
}
Expand Down Expand Up @@ -1084,6 +1092,7 @@ IUnresolvedMethod ReadMethod(MethodInfo method, IUnresolvedTypeDefinition parent
for (int i = 0; i < genericArguments.Length; i++) {
var tp = (DefaultUnresolvedTypeParameter)m.TypeParameters[i];
AddConstraints(tp, genericArguments[i]);
AddAttributes(genericArguments[i], tp);
tp.ApplyInterningProvider(interningProvider);
}
}
Expand Down Expand Up @@ -1214,6 +1223,7 @@ IUnresolvedMethod ReadConstructor(ConstructorInfo method, IUnresolvedTypeDefinit
for (int i = 0; i < genericArguments.Length; i++) {
var tp = (DefaultUnresolvedTypeParameter)m.TypeParameters[i];
AddConstraints(tp, genericArguments[i]);
AddAttributes(genericArguments[i], tp);
tp.ApplyInterningProvider(interningProvider);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ sealed class MyAttribute : Attribute {}
class Inner {}
}
}

public class ClassWithAttributeOnTypeParameter<[Double(2)] T> {}

[Guid ("790C6E0B-9194-4cc9-9426-A48A63185696"), InterfaceType (ComInterfaceType.InterfaceIsDual)]
[ComImport]
Expand Down
8 changes: 8 additions & 0 deletions ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,5 +1500,13 @@ public void AttributesUsingNestedMembers() {
var inner2MyAttr = attributedInner2.Attributes.Single(a => a.AttributeType.Name == "MyAttribute");
Assert.AreEqual(myAttribute2, inner2MyAttr.AttributeType);
}

[Test]
public void ClassWithAttributeOnTypeParameter()
{
var tp = GetTypeDefinition(typeof(ClassWithAttributeOnTypeParameter<>)).TypeParameters.Single();
var attr = tp.Attributes.Single();
Assert.AreEqual("DoubleAttribute", attr.AttributeType.Name);
}
}
}

0 comments on commit 86856e9

Please sign in to comment.