From c52663e51d1d3ca683c1754fc53119d9707e7437 Mon Sep 17 00:00:00 2001 From: Jb Evain Date: Sun, 17 Jan 2016 16:50:13 -0800 Subject: Fix clearing fullname cache for nested types; fix #248 --- Mono.Cecil/TypeDefinition.cs | 13 +++++++++++++ Mono.Cecil/TypeReference.cs | 11 ++++++++--- Test/Mono.Cecil.Tests/NestedTypesTests.cs | 28 ++++++++++++++++++++++++++++ 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/.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); + } } } -- cgit v1.2.3