Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using JetBrains.Annotations;
- namespace Cadwise.DressCode.JarJarBinks.Catalogue.Verification.Core.Scaffolding
- {
- internal class PropertyTreeObject
- {
- [CanBeNull]
- private readonly PropertyTreeObject _parent;
- [NotNull]
- private readonly Dictionary<string, object> _properties;
- protected PropertyTreeObject([CanBeNull] PropertyTreeObject parent)
- {
- _properties = new Dictionary<string, object>();
- _parent = parent;
- }
- protected T GetValue<T>([NotNull] string name)
- {
- Guard.ThrowIf.Argument.IsNull(name, nameof(name));
- if (_properties.TryGetValue(name, out var result))
- {
- return (T) result;
- }
- if (null == _parent)
- {
- return default(T);
- }
- return _parent.GetValue<T>(name);
- }
- protected void SetValue([NotNull] string name, [CanBeNull] object value)
- {
- Guard.ThrowIf.Argument.IsNull(name, nameof(name));
- _properties[name] = value;
- }
- }
- internal sealed class Example : PropertyTreeObject
- {
- public Example([CanBeNull] PropertyTreeObject parent)
- :
- base(parent)
- {
- }
- public Zygote Expected
- {
- get
- {
- return GetValue<Zygote>(nameof(Expected));
- }
- set
- {
- SetValue(nameof(Expected), value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement