From 75d15cdc3129b2df711d908c0901fb74ed6d10ac Mon Sep 17 00:00:00 2001 From: "agrath@gmail.com" Date: Sat, 2 Jul 2011 17:29:47 -1200 Subject: [PATCH] Made GetProperty break earlier if context/parent is null (prevents NRE) and slightly changed behaviour so that empty strings will go recursively to the parent. Added prefix to property access (_) which will cause the property to be looked up recursively. This syntax is used when you want to get the value recursively, but you want to still apply the IRazorDataTypeModel (as @Model.GetPropertyValue won't do that). Syntax is: @Model._propertyName - had to be a _ as that is legal c# --- .../RazorDynamicNode/DynamicBackingItem.cs | 22 ++++++++++++++----- .../RazorDynamicNode/DynamicNode.cs | 12 +++++++--- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicBackingItem.cs b/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicBackingItem.cs index 82c9bbdd37..e9a1e5362b 100644 --- a/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicBackingItem.cs +++ b/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicBackingItem.cs @@ -198,15 +198,27 @@ namespace umbraco.MacroEngines public IProperty GetProperty(string alias, bool recursive) { - if (!recursive) return GetProperty(alias); - if (IsNull()) return null; + bool propertyExists = false; + return GetProperty(alias, recursive, out propertyExists); + } + public IProperty GetProperty(string alias, bool recursive, out bool propertyExists) + { + if (!recursive) + { + return GetProperty(alias, out propertyExists); + } + if (IsNull()) + { + propertyExists = false; + return null; + } DynamicBackingItem context = this; - IProperty prop = this.GetProperty(alias); - while (prop == null) + IProperty prop = this.GetProperty(alias, out propertyExists); + while (prop == null || string.IsNullOrEmpty(prop.Value)) { context = context.Parent; - prop = context.GetProperty(alias); if (context == null) break; + prop = context.GetProperty(alias, out propertyExists); } if (prop != null) { diff --git a/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs b/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs index f7d125e54b..9eec1dc211 100644 --- a/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs +++ b/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs @@ -383,11 +383,17 @@ namespace umbraco.MacroEngines bool propertyExists = false; if (n != null) { - var data = n.GetProperty(name, out propertyExists); + bool recursive = false; + if (name.StartsWith("_")) + { + name = name.Substring(1, name.Length - 1); + recursive = true; + } + var data = n.GetProperty(name, recursive, out propertyExists); // check for nicer support of Pascal Casing EVEN if alias is camelCasing: if (data == null && name.Substring(0, 1).ToUpper() == name.Substring(0, 1) && !propertyExists) { - data = n.GetProperty(name.Substring(0, 1).ToLower() + name.Substring((1)), out propertyExists); + data = n.GetProperty(name.Substring(0, 1).ToLower() + name.Substring((1)), recursive, out propertyExists); } if (data != null) @@ -517,7 +523,7 @@ namespace umbraco.MacroEngines //integer int iResult = 0; - if (int.TryParse(string.Format("{0}", result), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out iResult)) + if (int.TryParse(string.Format("{0}", result), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out iResult)) { result = iResult; return true;