From a04ab6933d4a13f24456aba9a149422fd15f7b41 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 4 Dec 2010 20:17:20 +0100 Subject: [PATCH] CecilLoader: Don't import DynamicAttribute (it's imported as SharedType.Dynamic instead) --- .../TypeSystem/TypeSystemTests.cs | 9 +++++ .../TypeSystem/CecilLoader.cs | 34 ++++++++++++------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs index bf23905417..b6a6f7ea4a 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs @@ -69,6 +69,7 @@ namespace ICSharpCode.NRefactory.TypeSystem { ITypeDefinition testClass = testCasePC.GetClass(typeof(DynamicTest)); Assert.AreSame(SharedTypes.Dynamic, testClass.Properties.Single().ReturnType.Resolve(ctx)); + Assert.AreEqual(0, testClass.Properties.Single().Attributes.Count); } [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); } + [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] public void AssemblyAttribute() { diff --git a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs index 6a803d6f73..f9a8b7f536 100644 --- a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs +++ b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs @@ -271,12 +271,14 @@ namespace ICSharpCode.NRefactory.TypeSystem return new GetClassTypeReference(name, typeParameterCount); } + static readonly string DynamicAttributeFullName = typeof(DynamicAttribute).FullName; + static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex) { if (attributeProvider == null || !attributeProvider.HasCustomAttributes) return false; 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) { CustomAttributeArgument[] values = a.ConstructorArguments[0].Value as CustomAttributeArgument[]; 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) { if (customAttributeProvider.HasCustomAttributes) { - foreach (var cecilAttribute in customAttributeProvider.CustomAttributes) { - targetEntity.Attributes.Add(ReadAttribute(cecilAttribute)); - } + AddCustomAttributes(customAttributeProvider.CustomAttributes, targetEntity.Attributes); } } void AddAttributes(ParameterDefinition parameter, DefaultParameter targetParameter) { if (parameter.HasCustomAttributes) { - foreach (var cecilAttribute in parameter.CustomAttributes) { - targetParameter.Attributes.Add(ReadAttribute(cecilAttribute)); - } + AddCustomAttributes(parameter.CustomAttributes, targetParameter.Attributes); } } void AddAttributes(MethodDefinition accessorMethod, DefaultAccessor targetAccessor) { if (accessorMethod.HasCustomAttributes) { - foreach (var cecilAttribute in accessorMethod.CustomAttributes) { - targetAccessor.Attributes.Add(ReadAttribute(cecilAttribute)); - } + AddCustomAttributes(accessorMethod.CustomAttributes, targetAccessor.Attributes); } } @@ -371,8 +367,15 @@ namespace ICSharpCode.NRefactory.TypeSystem #endregion if (typeDefinition.HasCustomAttributes) { - foreach (var cecilAttribute in typeDefinition.CustomAttributes) { - targetEntity.Attributes.Add(ReadAttribute(cecilAttribute)); + AddCustomAttributes(typeDefinition.CustomAttributes, targetEntity.Attributes); + } + } + + void AddCustomAttributes(Mono.Collections.Generic.Collection attributes, IList 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); 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; if (valueType != null) value = ReadTypeReference(valueType);