From ff8e0a9d7505c11c1d485cce51b0a56865174dc6 Mon Sep 17 00:00:00 2001 From: Maurits van der Schee Date: Fri, 26 Aug 2022 15:04:06 +0200 Subject: [PATCH] update --- ViewData.cs | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 ViewData.cs diff --git a/ViewData.cs b/ViewData.cs new file mode 100644 index 0000000..6d6126a --- /dev/null +++ b/ViewData.cs @@ -0,0 +1,69 @@ +// See License.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Dynamic; + +namespace Maussoft.Mvc +{ + public class ViewData : DynamicObject + { + protected Dictionary dictionary; + + public ViewData() + { + this.dictionary = new Dictionary(); + } + + public ViewData(IDictionary dict) + { + this.dictionary = new Dictionary(); + + foreach (var kvp in dict) + { + this.dictionary.Add(kvp.Key, kvp.Value); + } + } + + public ViewData(IDictionary dict) + { + this.dictionary = new Dictionary(); + + foreach (var kvp in dict) + { + this.dictionary.Add(kvp.Key, kvp.Value); + } + } + + public ViewData(ViewData viewData) + { + this.dictionary = new Dictionary(); + + foreach (var kvp in viewData.dictionary) + { + this.dictionary.Add(kvp.Key, kvp.Value); + } + } + + public override IEnumerable GetDynamicMemberNames() + { + return dictionary.Keys; + } + + public override bool TryGetMember(GetMemberBinder binder, out object result) + { + result = dictionary.ContainsKey(binder.Name) ? dictionary[binder.Name] : null; + return true; + } + + public override bool TrySetMember(SetMemberBinder binder, object value) + { + dictionary[binder.Name] = value; + return true; + } + + public bool Empty() + { + return dictionary.Keys.Count == 0; + } + } +} \ No newline at end of file