forked from reflection-emit/Cauldron
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTestPropertyInterceptorAttribute.cs
More file actions
53 lines (44 loc) · 1.76 KB
/
TestPropertyInterceptorAttribute.cs
File metadata and controls
53 lines (44 loc) · 1.76 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
using Cauldron.Interception;
using System;
using Cauldron;
using System.Collections.Generic;
namespace UnitTest_InterceptorsForTest
{
using Cauldron;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class TestPropertyInterceptorAttribute : Attribute, IPropertyGetterInterceptor, IPropertySetterInterceptor
{
public bool OnException(Exception e) => true;
public void OnExit()
{
}
public void OnGet(PropertyInterceptionInfo propertyInterceptionInfo, object value)
{
if (Comparer.Equals(value, (long)30))
propertyInterceptionInfo.SetValue(9999);
if (Comparer.Equals(value, (double)66))
propertyInterceptionInfo.SetValue(78344.8f);
if (Comparer.Equals(value, (int)113))
propertyInterceptionInfo.SetValue(null);
}
public bool OnSet(PropertyInterceptionInfo propertyInterceptionInfo, object oldValue, object newValue)
{
if (propertyInterceptionInfo.PropertyType.IsArray || propertyInterceptionInfo.PropertyType.AreReferenceAssignable(typeof(List<long>)))
{
var passed = new List<long>();
passed.Add(2);
passed.Add(232);
passed.Add(5643);
passed.Add(52435);
propertyInterceptionInfo.SetValue(passed);
return true;
}
if (propertyInterceptionInfo.PropertyType == typeof(long) && Convert.ToInt64(newValue) == 66L)
{
propertyInterceptionInfo.SetValue(99L);
return true;
}
return false;
}
}
}