From 545f2861ef90322ab8d60451c5749892d4a25f33 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 16 Nov 2010 17:14:36 -0800 Subject: [PATCH] Catching exceptions before they are thrown when adding new shapes --HG-- branch : dev --- src/Orchard/DisplayManagement/Shapes/Shape.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Orchard/DisplayManagement/Shapes/Shape.cs b/src/Orchard/DisplayManagement/Shapes/Shape.cs index 64544175b..26efd10e0 100644 --- a/src/Orchard/DisplayManagement/Shapes/Shape.cs +++ b/src/Orchard/DisplayManagement/Shapes/Shape.cs @@ -1,5 +1,7 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; +using System.Web.Mvc; namespace Orchard.DisplayManagement.Shapes { public class Shape : IShape, IEnumerable { @@ -18,11 +20,19 @@ namespace Orchard.DisplayManagement.Shapes { public virtual Shape Add(object item, string position = DefaultPosition) { try { - ((dynamic)item).Metadata.Position = position; + // todo: (sebros) this is a temporary implementation to prevent common known scenarios throwing exceptions. The final solution would need to filter based on the fact that it is a Shape instance + if ( item is MvcHtmlString || + item is String ) { + // need to implement positioned wrapper for non-shape objects + } + else { + ((dynamic) item).Metadata.Position = position; + } } catch { - // need to implemented positioned wrapper for non-shape objects + // need to implement positioned wrapper for non-shape objects } + _items.Add(item); // not messing with position at the moment return this; }