From 42959a1db5fe137a74efa7df0bf68fb1b4417742 Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 12 Jan 2018 13:51:06 +0100 Subject: [PATCH] U4-10822 - fix breaking change --- .../Web/Mvc/RenderModelBinderTests.cs | 10 +++---- src/Umbraco.Web/Mvc/RenderModelBinder.cs | 30 +++++++++---------- .../Mvc/UmbracoViewPageOfTModel.cs | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs index d574ea4b25..e69b3e114a 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs @@ -41,14 +41,14 @@ namespace Umbraco.Tests.Web.Mvc [Test] public void BindModel_Null_Source_Returns_Null() { - Assert.IsNull(RenderModelBinder.Instance.BindModel(null, typeof(MyContent), CultureInfo.CurrentCulture)); + Assert.IsNull(RenderModelBinder.BindModel(null, typeof(MyContent), CultureInfo.CurrentCulture)); } [Test] public void BindModel_Returns_If_Same_Type() { var content = new MyContent(Mock.Of()); - var bound = RenderModelBinder.Instance.BindModel(content, typeof (IPublishedContent), CultureInfo.CurrentCulture); + var bound = RenderModelBinder.BindModel(content, typeof (IPublishedContent), CultureInfo.CurrentCulture); Assert.AreSame(content, bound); } @@ -57,7 +57,7 @@ namespace Umbraco.Tests.Web.Mvc { var content = new MyContent(Mock.Of()); var renderModel = new RenderModel(content, CultureInfo.CurrentCulture); - var bound = RenderModelBinder.Instance.BindModel(renderModel, typeof(IPublishedContent), CultureInfo.CurrentCulture); + var bound = RenderModelBinder.BindModel(renderModel, typeof(IPublishedContent), CultureInfo.CurrentCulture); Assert.AreSame(content, bound); } @@ -65,7 +65,7 @@ namespace Umbraco.Tests.Web.Mvc public void BindModel_IPublishedContent_To_RenderModel() { var content = new MyContent(Mock.Of()); - var bound = (IRenderModel)RenderModelBinder.Instance.BindModel(content, typeof(RenderModel), CultureInfo.CurrentCulture); + var bound = (IRenderModel)RenderModelBinder.BindModel(content, typeof(RenderModel), CultureInfo.CurrentCulture); Assert.AreSame(content, bound.Content); } @@ -73,7 +73,7 @@ namespace Umbraco.Tests.Web.Mvc public void BindModel_IPublishedContent_To_Generic_RenderModel() { var content = new MyContent(Mock.Of()); - var bound = (IRenderModel)RenderModelBinder.Instance.BindModel(content, typeof(RenderModel), CultureInfo.CurrentCulture); + var bound = (IRenderModel)RenderModelBinder.BindModel(content, typeof(RenderModel), CultureInfo.CurrentCulture); Assert.AreSame(content, bound.Content); } diff --git a/src/Umbraco.Web/Mvc/RenderModelBinder.cs b/src/Umbraco.Web/Mvc/RenderModelBinder.cs index 7ce4320baf..f1dc2cafd8 100644 --- a/src/Umbraco.Web/Mvc/RenderModelBinder.cs +++ b/src/Umbraco.Web/Mvc/RenderModelBinder.cs @@ -14,8 +14,8 @@ namespace Umbraco.Web.Mvc /// public class RenderModelBinder : DefaultModelBinder, IModelBinderProvider { - public static RenderModelBinder Instance = new RenderModelBinder(); - + public static RenderModelBinder Instance = new RenderModelBinder(); + /// /// Binds the model to a value by using the specified controller context and binding context. /// @@ -67,7 +67,7 @@ namespace Umbraco.Web.Mvc // to // { RenderModel, RenderModel, IPublishedContent } // - public object BindModel(object source, Type modelType, CultureInfo culture) + public static object BindModel(object source, Type modelType, CultureInfo culture) { // null model, return if (source == null) return null; @@ -140,22 +140,22 @@ namespace Umbraco.Web.Mvc SourceType = sourceType; ModelType = modelType; Message = message; - } + } public bool SourceIsContent; public bool ViewModelIsContent; public Type SourceType { get; set; } - public Type ModelType { get; set; } - public StringBuilder Message { get; private set; } + public Type ModelType { get; set; } + public StringBuilder Message { get; private set; } public bool Restart { get; set; } - } - - public static event EventHandler ModelBindingException; + } - private void ThrowModelBindingException(bool sourceContent, bool modelContent, Type sourceType, Type modelType) + public static event EventHandler ModelBindingException; + + private static void ThrowModelBindingException(bool sourceContent, bool modelContent, Type sourceType, Type modelType) { var msg = new StringBuilder(); - + // prepare message msg.Append("Cannot bind source"); if (sourceContent) msg.Append(" content"); @@ -166,14 +166,14 @@ namespace Umbraco.Web.Mvc msg.Append(" type "); msg.Append(modelType.FullName); msg.Append("."); - - // raise event, to give model factories a chance at reporting - // the error with more details, and optionally request that + + // raise event, to give model factories a chance at reporting + // the error with more details, and optionally request that // the application restarts. var args = new ModelBindingArgs(sourceType, modelType, msg); if (ModelBindingException != null) - ModelBindingException(this, args); + ModelBindingException(Instance, args); if (args.Restart) { diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index b364a76628..3d1a41d289 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -144,7 +144,7 @@ namespace Umbraco.Web.Mvc // bind the model (use context culture as default, if available) if (UmbracoContext.PublishedContentRequest != null && UmbracoContext.PublishedContentRequest.Culture != null) culture = UmbracoContext.PublishedContentRequest.Culture; - viewData.Model = RenderModelBinder.Instance.BindModel(viewDataModel, typeof (TModel), culture); + viewData.Model = RenderModelBinder.BindModel(viewDataModel, typeof (TModel), culture); // set the view data base.SetViewData(viewData);