Ejemplo n.º 1
0
        public static void Main()
        {
            ConstructorInvoker ctor    = Reflect.Constructor(typeof(Person), typeof(string), typeof(int));
            MemberGetter       getName = Reflect.Getter(typeof(Person), "Name");
            MemberGetter       getAge  = Reflect.FieldGetter(typeof(Person), "Age");
            MemberSetter       setAge  = Reflect.Setter(typeof(Person), "Age");
            MultiSetter        setBoth = Reflect.MultiSetter(typeof(Person), "Age", "Name");

            Person person = (Person)ctor("John Doe", 21);

            setAge(person, 30);
            Console.WriteLine(getName(person));
            Console.WriteLine(getAge(person));
            setBoth(person, 35, "John Wick");
            Console.WriteLine(getName(person));
            Console.WriteLine(getAge(person));
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            ConstructorInvoker ctor    = Reflect.Constructor(typeof(Animal), typeof(string), typeof(int));
            MemberGetter       getName = Reflect.Getter(typeof(Animal), "Name");
            MemberGetter       getAge  = Reflect.FieldGetter(typeof(Animal), "Age");
            MemberSetter       setAge  = Reflect.Setter(typeof(Animal), "Age");
            MultiSetter        setBoth = Reflect.MultiSetter(typeof(Animal), "Age", "Name");

            Animal          animal = (Animal)ctor("Charlie", 5);
            ValueTypeHolder holder = new ValueTypeHolder(animal);             // IMPORTANT!

            setAge(holder, 8);
            Console.WriteLine(getName(holder));
            Console.WriteLine(getAge(holder));
            setBoth(holder, 10, "Buster");
            Console.WriteLine(getName(holder));
            Console.WriteLine(getAge(holder));
            Console.ReadLine();
        }
 /// <summary>
 /// Creates a delegate which can get the value of the field identified by <paramref name="fieldInfo"/>.
 /// </summary>
 public static MemberGetter DelegateForGetFieldValue(this FieldInfo fieldInfo)
 {
     return(Reflect.FieldGetter(fieldInfo));
 }
 /// <summary>
 /// Gets the value of the instance field identified by <paramref name="fieldInfo"/> on the given <paramref name="obj"/>.
 /// </summary>
 public static object Get(this FieldInfo fieldInfo, object obj)
 {
     return(Reflect.FieldGetter(fieldInfo)(obj));
 }
 /// <summary>
 /// Gets the value of the static field identified by <paramref name="fieldInfo"/>.
 /// </summary>
 public static object Get(this FieldInfo fieldInfo)
 {
     return(Reflect.FieldGetter(fieldInfo)(null));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a delegate which can get the value of the field specified by <paramref name="name"/> and
 /// matching <paramref name="bindingFlags"/> on the given <paramref name="type"/>.
 /// </summary>
 public static MemberGetter DelegateForGetFieldValue(this Type type, string name, FasterflectFlags bindingFlags)
 {
     return(Reflect.FieldGetter(type, name, bindingFlags));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a delegate which can get the value of the field specified by <paramref name="name"/> on
 /// the given <paramref name="type"/>.
 /// </summary>
 public static MemberGetter DelegateForGetFieldValue(this Type type, string name)
 {
     return(Reflect.FieldGetter(type, name));
 }