2012-08-17 04:27:47 +06:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Dynamics
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DynamicDictionary : DynamicObject
|
|
|
|
|
|
{
|
2012-11-07 03:49:32 +05:00
|
|
|
|
internal readonly Dictionary<string, object> SourceItems;
|
|
|
|
|
|
|
2012-08-17 04:27:47 +06:00
|
|
|
|
public DynamicDictionary(Dictionary<string, object> sourceItems)
|
|
|
|
|
|
{
|
2012-11-07 03:49:32 +05:00
|
|
|
|
SourceItems = sourceItems;
|
2012-08-17 04:27:47 +06:00
|
|
|
|
}
|
|
|
|
|
|
public override bool TrySetMember(SetMemberBinder binder, object value)
|
|
|
|
|
|
{
|
2012-11-07 03:49:32 +05:00
|
|
|
|
if (SourceItems.ContainsKey(binder.Name))
|
2012-08-17 04:27:47 +06:00
|
|
|
|
{
|
2012-11-07 03:49:32 +05:00
|
|
|
|
SourceItems[binder.Name.ToLower()] = value;
|
2012-08-17 04:27:47 +06:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2012-11-07 03:49:32 +05:00
|
|
|
|
SourceItems.Add(binder.Name.ToLower(), value);
|
2012-08-17 04:27:47 +06:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
|
|
|
|
|
{
|
2012-11-07 03:49:32 +05:00
|
|
|
|
if (SourceItems != null)
|
2012-08-17 04:27:47 +06:00
|
|
|
|
{
|
2012-11-07 03:49:32 +05:00
|
|
|
|
if (SourceItems.TryGetValue(binder.Name.ToLower(), out result))
|
2012-08-17 04:27:47 +06:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result = null;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|