-
Notifications
You must be signed in to change notification settings - Fork 13
/
_Examples.cs
58 lines (50 loc) · 1.56 KB
/
_Examples.cs
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
//This code isn't meant to be compiled, it's just a list of examples that I've been lazy to put to their appropriate classes.
#if false
/* Extended reflection */
var asb = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("TestAsm"), AssemblyBuilderAccess.Save);
var modb = asb.DefineDynamicModule("TestAsm.dll");
var typ = modb.DefineType("TestType");
var sig = new MethodSignature(typeof(int).MakeModifiedType(typeof(int[])));
var mb = typ.DefineMethod("TestMethod", MethodAttributes.Public | MethodAttributes.Static, sig);
var il = mb.GetILGenerator();
il.Emit(OpCodes.Ret);
typ.DefineFieldExtended("fld", typeof(int).MakeModifiedType(new SignatureElementType(CorElementType.Sentinel)), FieldAttributes.Public);
typ.DefineField("fld", typeof(int), null, new[]{typeof(int?)}, FieldAttributes.Public);
typ.CreateType();
asb.Save("TestAsm.dll");
/* Proxy implementation */
class MarshalTest : MarshalByRefObject
{
public void Test(int arg1, ref int arg2, out int arg3)
{
arg3 = arg1+arg2;
arg2 *= 2;
}
}
interface IMarshalInterface : IProxyReplacer<MarshalTest, IMarshalInterface>
{
void Test(int arg1, ref int arg2, out int arg3);
}
class MarshalImpl : IMarshalInterface
{
public void Test(int arg1, ref int arg2, out int arg3)
{
arg3 = arg1-arg2;
arg2 /= 2;
}
}
var pr = ProxyImplementationBinder.GetProxy(new MarshalImpl());
int a = 10;
int b = 6;
int c;
pr.Test(a, ref b, out c);
/* Null reference check */
public static void TestRef(ref int i)
{
Console.WriteLine(Reference.IsNull(ref i));
}
unsafe{
int* a = null;
TestRef(ref *a);
}
#endif