RazorCore contains all the core razor engine implementation RazorDynamicNode contains all the DynamicNode functionality and associated support files
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Dynamic;
|
|
|
|
namespace umbraco.MacroEngines
|
|
{
|
|
public class DynamicDictionary : DynamicObject
|
|
{
|
|
Dictionary<string, object> _dictionary;
|
|
public DynamicDictionary(Dictionary<string, object> sourceItems)
|
|
{
|
|
_dictionary = sourceItems;
|
|
}
|
|
public override bool TrySetMember(SetMemberBinder binder, object value)
|
|
{
|
|
if (_dictionary.ContainsKey(binder.Name))
|
|
{
|
|
_dictionary[binder.Name.ToLower()] = value;
|
|
}
|
|
else
|
|
{
|
|
_dictionary.Add(binder.Name.ToLower(), value);
|
|
}
|
|
return true;
|
|
}
|
|
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
|
{
|
|
if (_dictionary != null)
|
|
{
|
|
if (_dictionary.TryGetValue(binder.Name.ToLower(), out result))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
result = null;
|
|
return true;
|
|
}
|
|
}
|
|
}
|