Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jb@evain.net>2016-01-18 03:50:13 +0300
committerJb Evain <jb@evain.net>2016-01-18 03:50:13 +0300
commitc52663e51d1d3ca683c1754fc53119d9707e7437 (patch)
tree587c74919e06caab2345afe4b0987ca383055dfe
parentdea1cc6da3533a5edca9a58d25089b9940d1bf4c (diff)
Fix clearing fullname cache for nested types; fix #248
-rw-r--r--Mono.Cecil/TypeDefinition.cs13
-rw-r--r--Mono.Cecil/TypeReference.cs11
-rw-r--r--Test/Mono.Cecil.Tests/NestedTypesTests.cs28
3 files changed, 49 insertions, 3 deletions
diff --git a/Mono.Cecil/TypeDefinition.cs b/Mono.Cecil/TypeDefinition.cs
index 226d7f3..5443746 100644
--- a/Mono.Cecil/TypeDefinition.cs
+++ b/Mono.Cecil/TypeDefinition.cs
@@ -442,6 +442,19 @@ namespace Mono.Cecil {
this.BaseType = baseType;
}
+ protected override void ClearFullName ()
+ {
+ base.ClearFullName ();
+
+ if (!HasNestedTypes)
+ return;
+
+ var nested_types = this.NestedTypes;
+
+ for (int i = 0; i < nested_types.Count; i++)
+ nested_types [i].ClearFullName ();
+ }
+
public override TypeDefinition Resolve ()
{
return this;
diff --git a/Mono.Cecil/TypeReference.cs b/Mono.Cecil/TypeReference.cs
index fce2023..1c25396 100644
--- a/Mono.Cecil/TypeReference.cs
+++ b/Mono.Cecil/TypeReference.cs
@@ -66,7 +66,7 @@ namespace Mono.Cecil {
get { return base.Name; }
set {
base.Name = value;
- fullname = null;
+ ClearFullName ();
}
}
@@ -74,7 +74,7 @@ namespace Mono.Cecil {
get { return @namespace; }
set {
@namespace = value;
- fullname = null;
+ ClearFullName ();
}
}
@@ -148,7 +148,7 @@ namespace Mono.Cecil {
get { return base.DeclaringType; }
set {
base.DeclaringType = value;
- fullname = null;
+ ClearFullName ();
}
}
@@ -241,6 +241,11 @@ namespace Mono.Cecil {
value_type = valueType;
}
+ protected virtual void ClearFullName ()
+ {
+ this.fullname = null;
+ }
+
public virtual TypeReference GetElementType ()
{
return this;
diff --git a/Test/Mono.Cecil.Tests/NestedTypesTests.cs b/Test/Mono.Cecil.Tests/NestedTypesTests.cs
index c840e63..38ae146 100644
--- a/Test/Mono.Cecil.Tests/NestedTypesTests.cs
+++ b/Test/Mono.Cecil.Tests/NestedTypesTests.cs
@@ -59,5 +59,33 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual ("Foo/<IFoo<System.Byte[]>.Do>d__0", foo_child.FullName);
});
}
+
+ [Test]
+ public void NestedTypeFullName ()
+ {
+ var foo = new TypeDefinition (null, "Foo", TypeAttributes.Class);
+ var bar = new TypeDefinition (null, "Bar", TypeAttributes.Class);
+ var baz = new TypeDefinition (null, "Baz", TypeAttributes.Class);
+
+ foo.NestedTypes.Add (bar);
+ bar.NestedTypes.Add (baz);
+
+ Assert.AreEqual ("Foo/Bar/Baz", baz.FullName);
+
+ foo.Namespace = "Change";
+
+ Assert.AreEqual ("Change.Foo/Bar", bar.FullName);
+ Assert.AreEqual ("Change.Foo/Bar/Baz", baz.FullName);
+
+ bar.Namespace = "AnotherChange";
+
+ Assert.AreEqual ("Change.Foo/AnotherChange.Bar", bar.FullName);
+ Assert.AreEqual ("Change.Foo/AnotherChange.Bar/Baz", baz.FullName);
+
+ foo.Name = "FooFoo";
+
+ Assert.AreEqual ("Change.FooFoo/AnotherChange.Bar", bar.FullName);
+ Assert.AreEqual ("Change.FooFoo/AnotherChange.Bar/Baz", baz.FullName);
+ }
}
}