Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Aug 26, 2022
1 parent c09cb72 commit ff8e0a9
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions ViewData.cs
Original file line number Diff line number Diff line change
@@ -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<string, object> dictionary;

public ViewData()
{
this.dictionary = new Dictionary<string, object>();
}

public ViewData(IDictionary<string, object> dict)
{
this.dictionary = new Dictionary<string, object>();

foreach (var kvp in dict)
{
this.dictionary.Add(kvp.Key, kvp.Value);
}
}

public ViewData(IDictionary<string, string> dict)
{
this.dictionary = new Dictionary<string, object>();

foreach (var kvp in dict)
{
this.dictionary.Add(kvp.Key, kvp.Value);
}
}

public ViewData(ViewData viewData)
{
this.dictionary = new Dictionary<string, object>();

foreach (var kvp in viewData.dictionary)
{
this.dictionary.Add(kvp.Key, kvp.Value);
}
}

public override IEnumerable<string> 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;
}
}
}

0 comments on commit ff8e0a9

Please sign in to comment.