2011-01-26 08:28:16 -13:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2011-02-06 19:52:05 -13:00
|
|
|
|
if (_dictionary.ContainsKey(binder.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
_dictionary[binder.Name.ToLower()] = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_dictionary.Add(binder.Name.ToLower(), value);
|
|
|
|
|
|
}
|
2011-01-26 08:28:16 -13:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|