Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- namespace Test
- {
- public class A { }
- public class B : A { }
- public class Class
- {
- public A a = new A();
- }
- class Program
- {
- static void Main(string[] args)
- {
- var y = typeof(B);
- var x = typeof(Class).GetField("a");
- var type = x.GetType();
- Console.WriteLine(x);
- FieldInfo fieldInfo = null;
- for (; type != null && fieldInfo == null; type = type.BaseType)
- fieldInfo = type.GetField("type", BindingFlags.Instance | BindingFlags.NonPublic);
- fieldInfo.SetValue(x, y);
- Console.WriteLine(typeof(Class).GetField("a"));
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement