Yeah that's interesting actually.
If you box the struct first it works, eg.
If you box the struct first it works, eg.
1 public struct test
2 {
3 public string name;
4 }
5
6 static void Main()
7 {
8 test t = new test();
9 FieldInfo fi = t.GetType().GetField("name");
10 object p = (object)t;
11 fi.SetValue(p, "blah");
12 t = (test)p;
13 Console.WriteLine(t.name);
14 Console.ReadLine();
15 }
16
2 {
3 public string name;
4 }
5
6 static void Main()
7 {
8 test t = new test();
9 FieldInfo fi = t.GetType().GetField("name");
10 object p = (object)t;
11 fi.SetValue(p, "blah");
12 t = (test)p;
13 Console.WriteLine(t.name);
14 Console.ReadLine();
15 }
16
浙公网安备 33010602011771号