-
Notifications
You must be signed in to change notification settings - Fork 772
Expand file tree
/
Copy pathdlrtest.cs
More file actions
31 lines (23 loc) · 1.03 KB
/
dlrtest.cs
File metadata and controls
31 lines (23 loc) · 1.03 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
using System.Collections.Generic;
using System.Dynamic;
namespace Python.Test;
public class DynamicMappingObject : DynamicObject
{
readonly Dictionary<string, object> storage = [];
// Native members for testing that regular CLR access is unaffected.
public string Label = "default";
public int Multiplier { get; set; } = 1;
public int Multiply(int value) => value * Multiplier;
// Test helper: bypass normal member binding and write directly to dynamic storage.
public void SetDynamicValue(string name, object value) => storage[name] = value;
public override bool TryGetMember(GetMemberBinder binder, out object result)
=> storage.TryGetValue(binder.Name, out result);
public override bool TrySetMember(SetMemberBinder binder, object value)
{
storage[binder.Name] = value;
return true;
}
public override bool TryDeleteMember(DeleteMemberBinder binder)
=> storage.Remove(binder.Name);
public override IEnumerable<string> GetDynamicMemberNames() => storage.Keys;
}