-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (39 loc) · 1.72 KB
/
Program.cs
File metadata and controls
71 lines (39 loc) · 1.72 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
using DispatchProxyAdvanced;
using Examples;
Console.WriteLine("=== Example 1: Interface ===");
var proxy1 = ProxyFactory.Create<IExampleInterface>((method, args) =>
{
Console.WriteLine($"Executing method: {method.Name}, with args: {string.Join(", ", args)}");
return args.FirstOrDefault();
});
proxy1.MyProp = 222;
proxy1.MyMethod(20, 200);
Console.WriteLine("\n=== Example 2: Abstract class ===");
var proxy2 = ProxyFactory.Create<ExampleAbstractClass>((method, args) =>
{
Console.WriteLine($"Executing method: {method.Name}, with args: {string.Join(", ", args)}");
return args.FirstOrDefault();
});
proxy2.MyProp = 333;
proxy2.MyMethod(30, 300);
Console.WriteLine("\n=== Example 3: Simple class ===");
var someInstance = new ExampleClass { MyProp = 111 };
var proxy3 = ProxyFactory.CreateSourced(someInstance, (source, method, args) =>
{
Console.WriteLine($"Executing method: {method.Name}, with args: {string.Join(", ", args)}");
return method.Invoke(source, args);
});
Console.WriteLine($"Property value: {proxy3.MyProp}");
Console.WriteLine($"Method result: {proxy3.MyMethod(10, 100)}");
Console.WriteLine("\n=== Example 4: Custom proxy state ===");
var proxy4 = ProxyFactory.CreateSourced(someInstance, (source, proxy, method, args) =>
{
// set your custom state to proxy instance
proxy.CustomProxyStateDefinition = "ExampleStateValue";
Console.WriteLine($"Executing method: {method.Name}");
return method.Invoke(source, args);
});
Console.WriteLine($"Start proxy state: '{((IProxy)proxy4).CustomProxyStateDefinition}'");
proxy4.MyMethod(10, 100);
Console.WriteLine($"Current proxy state: '{((IProxy)proxy4).CustomProxyStateDefinition}'");
Console.WriteLine("\n=== done ===");