Skip to content

Commit ff8e0a9

Browse files
committed
update
1 parent c09cb72 commit ff8e0a9

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

ViewData.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// See License.txt in the project root for license information.
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Dynamic;
5+
6+
namespace Maussoft.Mvc
7+
{
8+
public class ViewData : DynamicObject
9+
{
10+
protected Dictionary<string, object> dictionary;
11+
12+
public ViewData()
13+
{
14+
this.dictionary = new Dictionary<string, object>();
15+
}
16+
17+
public ViewData(IDictionary<string, object> dict)
18+
{
19+
this.dictionary = new Dictionary<string, object>();
20+
21+
foreach (var kvp in dict)
22+
{
23+
this.dictionary.Add(kvp.Key, kvp.Value);
24+
}
25+
}
26+
27+
public ViewData(IDictionary<string, string> dict)
28+
{
29+
this.dictionary = new Dictionary<string, object>();
30+
31+
foreach (var kvp in dict)
32+
{
33+
this.dictionary.Add(kvp.Key, kvp.Value);
34+
}
35+
}
36+
37+
public ViewData(ViewData viewData)
38+
{
39+
this.dictionary = new Dictionary<string, object>();
40+
41+
foreach (var kvp in viewData.dictionary)
42+
{
43+
this.dictionary.Add(kvp.Key, kvp.Value);
44+
}
45+
}
46+
47+
public override IEnumerable<string> GetDynamicMemberNames()
48+
{
49+
return dictionary.Keys;
50+
}
51+
52+
public override bool TryGetMember(GetMemberBinder binder, out object result)
53+
{
54+
result = dictionary.ContainsKey(binder.Name) ? dictionary[binder.Name] : null;
55+
return true;
56+
}
57+
58+
public override bool TrySetMember(SetMemberBinder binder, object value)
59+
{
60+
dictionary[binder.Name] = value;
61+
return true;
62+
}
63+
64+
public bool Empty()
65+
{
66+
return dictionary.Keys.Count == 0;
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)