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#

This commit is contained in:
agrath@gmail.com
2011-07-02 17:29:47 -12:00
parent 49a0c8a11a
commit 75d15cdc31
2 changed files with 26 additions and 8 deletions

View File

@@ -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)
{

View File

@@ -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;