Starting writing a few unit tests for the new DynamicNode codebase. Will of course leave the original DynamicNode stuff in its current place for backwards compatibility but will deprecate many of the classes which will call the new ones.
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Dynamic;
|
|
|
|
namespace Umbraco.Core.Dynamics
|
|
{
|
|
public class DynamicDictionary : DynamicObject
|
|
{
|
|
readonly 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;
|
|
}
|
|
}
|
|
}
|