Browse Source

CecilLoader: Don't import DynamicAttribute (it's imported as SharedType.Dynamic instead)

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
a04ab6933d
  1. 9
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  2. 34
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

9
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -69,6 +69,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
ITypeDefinition testClass = testCasePC.GetClass(typeof(DynamicTest)); ITypeDefinition testClass = testCasePC.GetClass(typeof(DynamicTest));
Assert.AreSame(SharedTypes.Dynamic, testClass.Properties.Single().ReturnType.Resolve(ctx)); Assert.AreSame(SharedTypes.Dynamic, testClass.Properties.Single().ReturnType.Resolve(ctx));
Assert.AreEqual(0, testClass.Properties.Single().Attributes.Count);
} }
[Test] [Test]
@ -99,6 +100,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
Assert.AreEqual("System.Action`3[[System.Int32[][,]],[dynamic],[System.Object]]", m7.Parameters[0].Type.Resolve(ctx).ReflectionName); Assert.AreEqual("System.Action`3[[System.Int32[][,]],[dynamic],[System.Object]]", m7.Parameters[0].Type.Resolve(ctx).ReflectionName);
} }
[Test]
public void DynamicParameterHasNoAttributes()
{
ITypeDefinition testClass = testCasePC.GetClass(typeof(DynamicTest));
IMethod m1 = testClass.Methods.Single(me => me.Name == "DynamicGenerics1");
Assert.AreEqual(0, m1.Parameters[0].Attributes.Count);
}
[Test] [Test]
public void AssemblyAttribute() public void AssemblyAttribute()
{ {

34
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -271,12 +271,14 @@ namespace ICSharpCode.NRefactory.TypeSystem
return new GetClassTypeReference(name, typeParameterCount); return new GetClassTypeReference(name, typeParameterCount);
} }
static readonly string DynamicAttributeFullName = typeof(DynamicAttribute).FullName;
static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex) static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex)
{ {
if (attributeProvider == null || !attributeProvider.HasCustomAttributes) if (attributeProvider == null || !attributeProvider.HasCustomAttributes)
return false; return false;
foreach (CustomAttribute a in attributeProvider.CustomAttributes) { foreach (CustomAttribute a in attributeProvider.CustomAttributes) {
if (a.Constructor.DeclaringType.FullName == typeof(DynamicAttribute).FullName) { if (a.Constructor.DeclaringType.FullName == DynamicAttributeFullName) {
if (a.ConstructorArguments.Count == 1) { if (a.ConstructorArguments.Count == 1) {
CustomAttributeArgument[] values = a.ConstructorArguments[0].Value as CustomAttributeArgument[]; CustomAttributeArgument[] values = a.ConstructorArguments[0].Value as CustomAttributeArgument[];
if (values != null && typeIndex < values.Length && values[typeIndex].Value is bool) if (values != null && typeIndex < values.Length && values[typeIndex].Value is bool)
@ -293,27 +295,21 @@ namespace ICSharpCode.NRefactory.TypeSystem
void AddAttributes(ICustomAttributeProvider customAttributeProvider, IEntity targetEntity) void AddAttributes(ICustomAttributeProvider customAttributeProvider, IEntity targetEntity)
{ {
if (customAttributeProvider.HasCustomAttributes) { if (customAttributeProvider.HasCustomAttributes) {
foreach (var cecilAttribute in customAttributeProvider.CustomAttributes) { AddCustomAttributes(customAttributeProvider.CustomAttributes, targetEntity.Attributes);
targetEntity.Attributes.Add(ReadAttribute(cecilAttribute));
}
} }
} }
void AddAttributes(ParameterDefinition parameter, DefaultParameter targetParameter) void AddAttributes(ParameterDefinition parameter, DefaultParameter targetParameter)
{ {
if (parameter.HasCustomAttributes) { if (parameter.HasCustomAttributes) {
foreach (var cecilAttribute in parameter.CustomAttributes) { AddCustomAttributes(parameter.CustomAttributes, targetParameter.Attributes);
targetParameter.Attributes.Add(ReadAttribute(cecilAttribute));
}
} }
} }
void AddAttributes(MethodDefinition accessorMethod, DefaultAccessor targetAccessor) void AddAttributes(MethodDefinition accessorMethod, DefaultAccessor targetAccessor)
{ {
if (accessorMethod.HasCustomAttributes) { if (accessorMethod.HasCustomAttributes) {
foreach (var cecilAttribute in accessorMethod.CustomAttributes) { AddCustomAttributes(accessorMethod.CustomAttributes, targetAccessor.Attributes);
targetAccessor.Attributes.Add(ReadAttribute(cecilAttribute));
}
} }
} }
@ -371,8 +367,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
#endregion #endregion
if (typeDefinition.HasCustomAttributes) { if (typeDefinition.HasCustomAttributes) {
foreach (var cecilAttribute in typeDefinition.CustomAttributes) { AddCustomAttributes(typeDefinition.CustomAttributes, targetEntity.Attributes);
targetEntity.Attributes.Add(ReadAttribute(cecilAttribute)); }
}
void AddCustomAttributes(Mono.Collections.Generic.Collection<CustomAttribute> attributes, IList<IAttribute> targetCollection)
{
foreach (var cecilAttribute in attributes) {
if (cecilAttribute.AttributeType.FullName != DynamicAttributeFullName) {
targetCollection.Add(ReadAttribute(cecilAttribute));
} }
} }
} }
@ -412,6 +415,13 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
ITypeReference type = ReadTypeReference(arg.Type); ITypeReference type = ReadTypeReference(arg.Type);
object value = arg.Value; object value = arg.Value;
CustomAttributeArgument[] array = value as CustomAttributeArgument[];
if (array != null) {
// TODO: write unit test for this
// TODO: are multi-dimensional arrays possible as well?
throw new NotImplementedException();
}
TypeReference valueType = value as TypeReference; TypeReference valueType = value as TypeReference;
if (valueType != null) if (valueType != null)
value = ReadTypeReference(valueType); value = ReadTypeReference(valueType);

Loading…
Cancel
Save