Updates to fetching extension methods in a more stable way in DynamicNodeList
This commit is contained in:
@@ -13,7 +13,7 @@ namespace umbraco.MacroEngines
|
||||
protected IParameterDictionary ParameterDictionary;
|
||||
protected ICultureDictionary CultureDictionary;
|
||||
|
||||
public dynamic Parameter { get { return ParameterDictionary; } }
|
||||
public dynamic MacroParameters { get { return ParameterDictionary; } }
|
||||
public dynamic Dictionary { get { return CultureDictionary; } }
|
||||
|
||||
public MacroModel Macro { get { return _macro; } }
|
||||
|
||||
@@ -219,6 +219,10 @@ namespace umbraco.MacroEngines
|
||||
}
|
||||
|
||||
MethodInfo firstMethod = methods.First();
|
||||
// NH: this is to ensure that it's always the correct one being chosen when using the LINQ extension methods
|
||||
if (methods.Count > 1)
|
||||
firstMethod = methods.First(x => x.IsGenericMethodDefinition);
|
||||
|
||||
MethodInfo methodToExecute = null;
|
||||
if (firstMethod.IsGenericMethodDefinition)
|
||||
{
|
||||
|
||||
@@ -5,32 +5,47 @@ using System.Dynamic;
|
||||
using umbraco.cms.businesslogic.macro;
|
||||
using System.Linq;
|
||||
|
||||
namespace umbraco.MacroEngines {
|
||||
namespace umbraco.MacroEngines
|
||||
{
|
||||
|
||||
public class UmbracoParameterDictionary : DynamicObject, IParameterDictionary {
|
||||
public class UmbracoParameterDictionary : DynamicObject, IParameterDictionary
|
||||
{
|
||||
|
||||
private readonly IEnumerable<MacroPropertyModel> _paramsKeyValue;
|
||||
|
||||
public UmbracoParameterDictionary(IEnumerable<MacroPropertyModel> paramsKeyValue) {
|
||||
public UmbracoParameterDictionary(IEnumerable<MacroPropertyModel> paramsKeyValue)
|
||||
{
|
||||
_paramsKeyValue = paramsKeyValue;
|
||||
if (_paramsKeyValue == null)
|
||||
_paramsKeyValue = new List<MacroPropertyModel>();
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, string>> GetEnumerator() {
|
||||
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
||||
{
|
||||
return _paramsKeyValue.Select(p => new KeyValuePair<string, string>(p.Key, p.Value)).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public string this[string alias] {
|
||||
public string this[string alias]
|
||||
{
|
||||
get { return _paramsKeyValue.Where(p => p.Key == alias).Select(p => p.Value).FirstOrDefault(); }
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result) {
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
||||
{
|
||||
result = this[binder.Name];
|
||||
|
||||
// we'll check if parameters no matter the casing (due to the macro parser lower case all parameter aliases)
|
||||
if (result == null || String.IsNullOrEmpty(result.ToString()))
|
||||
{
|
||||
|
||||
if (this.Any(x => x.Key.ToLower() == binder.Name.ToLower()))
|
||||
result = this.First(x => x.Key.ToLower() == binder.Name.ToLower()).Value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user