-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewData.cs
69 lines (57 loc) · 1.76 KB
/
ViewData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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;
}
}
}