forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (55 loc) · 1.69 KB
/
Program.cs
File metadata and controls
70 lines (55 loc) · 1.69 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
using System;
namespace ServiceStack.Text.TestsConsole
{
public struct T
{
public int PropValue { get; set; }
public string PropRef { get; set; }
public int FieldValue;
public string FieldRef;
}
class Program
{
static void Main(string[] args)
{
var t = new T { PropValue = 1, PropRef = "foo", FieldValue = 2, FieldRef = "bar" };
//var i1 = GetPropInt(t);
//var s1 = GetPropString(t);
//var i2 = GetFieldInt(t);
//var s2 = GetFieldString(t);
//$"PropValue: ${i1}, PropRef: ${s1}".Print();
//$"FieldValue: ${i2}, FieldRef: ${s2}".Print();
var tuple = ((int i, string s))new ValueTuple<int,string>(1,"foo");
var oTuple = (object) tuple;
var value = GetValueTupleItem2(oTuple);
value.PrintDump();
}
static object GetPropInt(object instance)
{
var t = (T)instance;
return t.PropValue;
}
static object GetPropString(object instance)
{
var t = (T)instance;
return t.PropRef;
}
static object GetFieldInt(object instance)
{
var t = (T)instance;
return t.FieldValue;
}
static object GetFieldString(object instance)
{
return ((T)instance).FieldRef;
}
static object GetValueTupleItem1(object instance)
{
return ((ValueTuple<int, string>)instance).Item1;
}
static object GetValueTupleItem2(object instance)
{
return ((ValueTuple<int, string>)instance).Item2;
}
}
}