From 9f1d212375058cd784e6bdaf6dddf8527be8cb70 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 11 Sep 2013 11:57:15 +1000 Subject: [PATCH 1/2] Implements: U4-2824 Type Converter for string type with unit test --- src/Umbraco.Core/ObjectExtensions.cs | 3 +++ src/Umbraco.Tests/ObjectExtensionsTests.cs | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/ObjectExtensions.cs b/src/Umbraco.Core/ObjectExtensions.cs index 434f71cb18..5bc8e46161 100644 --- a/src/Umbraco.Core/ObjectExtensions.cs +++ b/src/Umbraco.Core/ObjectExtensions.cs @@ -83,6 +83,9 @@ namespace Umbraco.Core if (input.GetType() == destinationType) return new Attempt(true, input); + //check for string so that overloaders of ToString() can take advantage of the conversion. + if (destinationType == typeof(string)) return new Attempt(true, input.ToString()); + if (!destinationType.IsGenericType || destinationType.GetGenericTypeDefinition() != typeof(Nullable<>)) { //TODO: Do a check for destination type being IEnumerable and source type implementing IEnumerable with diff --git a/src/Umbraco.Tests/ObjectExtensionsTests.cs b/src/Umbraco.Tests/ObjectExtensionsTests.cs index 788a28c4f4..6829e61a4f 100644 --- a/src/Umbraco.Tests/ObjectExtensionsTests.cs +++ b/src/Umbraco.Tests/ObjectExtensionsTests.cs @@ -115,7 +115,16 @@ namespace Umbraco.Tests } } - /// + [Test] + public virtual void CanConvertObjectToString_Using_ToString_Overload() + { + var result = new MyTestObject().TryConvertTo(); + + Assert.IsTrue(result.Success); + Assert.AreEqual("Hello world", result.Result); + } + + /// /// Run once before each test in derived test fixtures. /// public override void TestSetup() @@ -130,5 +139,13 @@ namespace Umbraco.Tests { return; } + + private class MyTestObject + { + public override string ToString() + { + return "Hello world"; + } + } } } \ No newline at end of file From 90abe8c25f867bdc20622ef9bda82f949f9062ef Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 11 Sep 2013 12:15:29 +1000 Subject: [PATCH 2/2] Fixes: U4-2823 RenderRouteHandler.GetUmbracoRouteDefinition() fails to store the route definition when an incidental alias-controller match is made --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 4 ++-- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index f9d60fbacb..02ddb3454b 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -2608,8 +2608,8 @@ - - + + diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index 1ebfebf1e4..56c4059f95 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -305,8 +305,9 @@ namespace Umbraco.Web.Mvc () => controllerType.FullName, () => typeof(IRenderMvcController).FullName, () => typeof(ControllerBase).FullName); - //exit as we cannnot route to the custom controller, just route to the standard one. - return def; + + //we cannot route to this custom controller since it is not of the correct type so we'll continue with the defaults + // that have already been set above. } }