More graceful handling of missing properties in .Where - TryGetMember now returns DynamicNull
Only return DynamicNull if property truely doesn't exist - if it does exist and has no value, still return null
This commit is contained in:
@@ -205,20 +205,21 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
|
||||
var name = binder.Name;
|
||||
result = null; //this will never be returned
|
||||
|
||||
if (name == "ChildrenAsList" || name == "Children")
|
||||
{
|
||||
result = GetChildrenAsList;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool propertyExists = false;
|
||||
if (n != null)
|
||||
{
|
||||
var data = n.GetProperty(name);
|
||||
var data = n.GetProperty(name, 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))
|
||||
if (data == null && name.Substring(0, 1).ToUpper() == name.Substring(0, 1) && !propertyExists)
|
||||
{
|
||||
data = n.GetProperty(name.Substring(0, 1).ToLower() + name.Substring((1)));
|
||||
data = n.GetProperty(name.Substring(0, 1).ToLower() + name.Substring((1)), out propertyExists);
|
||||
}
|
||||
|
||||
if (data != null)
|
||||
@@ -267,8 +268,15 @@ namespace umbraco.MacroEngines
|
||||
//at this point, we're going to return null
|
||||
//instead, we return a DynamicNull - see comments in that file
|
||||
//this will let things like Model.ChildItem work and return nothing instead of crashing
|
||||
result = new DynamicNull();
|
||||
//changed this to a return true because it breaks testing when using .Children().Random().propertyName
|
||||
if (!propertyExists && result == null)
|
||||
{
|
||||
//.Where explictly checks for this type
|
||||
//and will make it false
|
||||
//which means backwards equality (&& property != true) will pass
|
||||
//forwwards equality (&& property or && property == true) will fail
|
||||
result = new DynamicNull();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,5 +26,9 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1471,7 +1471,7 @@ namespace System.Linq.Dynamic
|
||||
Expression.IfThen(
|
||||
Expression.TypeEqual(result, typeof(DynamicNull)),
|
||||
Expression.Assign(result,
|
||||
Expression.Constant(true, typeof(object))
|
||||
Expression.Constant(false, typeof(object))
|
||||
)
|
||||
),
|
||||
Expression.Return(blockReturnLabel, result),
|
||||
|
||||
Reference in New Issue
Block a user