Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathModelObject.cs
More file actions
Latest commit
executable file
·80 lines (62 loc) · 2.02 KB
/
Copy pathModelObject.cs
File metadata and controls
executable file
·80 lines (62 loc) · 2.02 KB
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
70
71
72
73
74
75
76
77
78
79
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.Dynamic;
namespaceResourceExtractor;
internalclassModelObject:DynamicObject,IEnumerable<KeyValuePair<string,object>>{
privatereadonlyIDictionary<string,object>map=newDictionary<string,object>();
publicoverrideboolTryGetMember(GetMemberBinderbinder,outobjectresult)=>
map.TryGetValue(binder.Name,outresult);
publicoverrideboolTrySetMember(SetMemberBinderbinder,objectvalue){
if(value!=null){
map[binder.Name]=value;
}else{
map.Remove(binder.Name);
}
returntrue;
}
publicoverrideboolTryGetIndex(GetIndexBinderbinder,object[]indexes,outobjectresult){
result=null;
returnindexes.Length==1&&indexes[0]isstringname&&map.TryGetValue(name,outresult);
}
publicoverrideboolTrySetIndex(SetIndexBinderbinder,object[]indexes,objectvalue){
if(indexes.Length!=1||indexes[0]is not stringname){
returnfalse;
}
if(value!=null){
map[name]=value;
}else{
map.Remove(name);
}
returntrue;
}
publicoverrideboolTryDeleteMember(DeleteMemberBinderbinder){
map.Remove(binder.Name);
returntrue;
}
publicoverrideboolTryDeleteIndex(DeleteIndexBinderbinder,object[]indexes){
if(indexes.Length!=1||indexes[0]is not stringname){
returnfalse;
}
map.Remove(name);
returntrue;
}
publicvoidAdd(stringkey,objectvalue)=>
map.Add(key,value);
publicvoidAdd(KeyValuePair<string,object>item)=>
map.Add(item);
publicvoidRemove(stringkey)=>
map.Remove(key);
publicvoidRemove(KeyValuePair<string,object>item)=>
map.Remove(item);
publicvoidMerge(ModelObjectother){
foreach(varpairinother){
map[pair.Key]=pair.Value;
}
}
publicboolContainsKey(stringkey)=>
map.ContainsKey(key);
IEnumerator<KeyValuePair<string,object>>IEnumerable<KeyValuePair<string,object>>.GetEnumerator()=>
map.GetEnumerator();
IEnumeratorIEnumerable.GetEnumerator()=>
map.GetEnumerator();
}