Contribution by Piotr.

Fix workitem #17872: Null shape added to Zone causes NotImplementedException being thrown (return to change listing).
Added handling of null shapes. If shape that gets passed to Add method is null - it is simply ignored.

--HG--
branch : contributions
This commit is contained in:
Suha Can
2011-05-31 12:38:34 -07:00
parent 13d921a648
commit 1dbc40c6ac
3 changed files with 11 additions and 1 deletions

View File

@@ -19,6 +19,11 @@ namespace Orchard.DisplayManagement.Shapes {
public virtual IEnumerable<dynamic> Items { get { return _items; } }
public virtual Shape Add(object item, string position = DefaultPosition) {
// pszmyd: Ignoring null shapes
if (item == null) {
return this;
}
try {
// 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 ||

View File

@@ -35,7 +35,8 @@ namespace Orchard.UI {
public virtual string ZoneName { get; set; }
public IZone Add(Action<HtmlHelper> action, string position) {
throw new NotImplementedException();
// pszmyd: Replaced the NotImplementedException with simply doing nothing
return this;
}
}
}

View File

@@ -89,6 +89,10 @@ namespace Orchard.UI.Zones {
public override object InvokeMember(Func<object> proceed, object self, string name, INamedEnumerable<object> args) {
var argsCount = args.Count();
if (name == "Add" && (argsCount == 1 || argsCount == 2)) {
// pszmyd: Ignore null shapes
if (args.First() == null)
return _parent;
dynamic parent = _parent;
dynamic zone = _zoneFactory();