Ejemplo n.º 1
0
 public static int GetWeight(MyClass obj)
 {
     return(obj.Weight);
 }
Ejemplo n.º 2
0
 public static void SetName(MyClass obj, string name)
 {
     obj.Name = name;
 }
Ejemplo n.º 3
0
 public static void SetAge(MyClass obj, int age)
 {
     obj.Age = age;
 }
Ejemplo n.º 4
0
        internal static void PropertyReflectTest()
        {
            {
                var fGetter = PropertyReflector.MakeObjectFieldGetter(PropertyReflector.GetField(typeof(MyClass), "Name"));
                var fSetter = PropertyReflector.MakeObjectFieldSetter(PropertyReflector.GetField(typeof(MyClass), "Name"));

                var pGetter = PropertyReflector.MakeObjectPropertyGetter(PropertyReflector.GetProperty(typeof(MyClass), "Weight"));
                var pSetter = PropertyReflector.MakeObjectPropertySetter(PropertyReflector.GetProperty(typeof(MyClass), "Weight"));

                try
                {
                    var mc1 = new MyClass();

                    var name = "Chris";
                    fSetter(mc1, name);
                    var rname = fGetter(mc1);
                    if (name != (string)rname)
                    {
                        throw new Exception();
                    }

                    var weight = 62;
                    pSetter(mc1, weight);
                    var rweight = (int)pGetter(mc1);
                    if (weight != rweight)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("****** PropertyReflectTest() test failed");
                    throw;
                }
            }

            {
                var fGetter = PropertyReflector <MyClass, string> .GetFieldGetterFunc("Name");

                var fSetter = PropertyReflector <MyClass, string> .GetFieldSetterFunc("Name");

                var pGetter = PropertyReflector <MyClass, int> .GetPropertyGetterFunc("Weight");

                var pSetter = PropertyReflector <MyClass, int> .GetPropertySetterFunc("Weight");

                try
                {
                    var mc1 = new MyClass();

                    var name = "Chris";
                    fSetter(mc1, name);
                    var rname = fGetter(mc1);
                    if (name != rname)
                    {
                        throw new Exception();
                    }

                    var weight = 62;
                    pSetter(mc1, weight);
                    var rweight = pGetter(mc1);
                    if (weight != rweight)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("****** PropertyReflectTest() generic test failed");
                    throw;
                }
            }
        }
Ejemplo n.º 5
0
 public static int GetWeight(MyClass obj)
 {
     return obj.Weight;
 }
Ejemplo n.º 6
0
        internal static void PropertyReflectTest()
        {
            {
                var fGetter = PropertyReflector.MakeObjectFieldGetter(PropertyReflector.GetField(typeof(MyClass), "Name"));
                var fSetter = PropertyReflector.MakeObjectFieldSetter(PropertyReflector.GetField(typeof(MyClass), "Name"));

                var pGetter = PropertyReflector.MakeObjectPropertyGetter(PropertyReflector.GetProperty(typeof(MyClass), "Weight"));
                var pSetter = PropertyReflector.MakeObjectPropertySetter(PropertyReflector.GetProperty(typeof(MyClass), "Weight"));

                try
                {
                    var mc1 = new MyClass();

                    var name = "Chris";
                    fSetter(mc1, name);
                    var rname = fGetter(mc1);
                    if (name != (string)rname)
                    {
                        throw new Exception();
                    }

                    var weight = 62;
                    pSetter(mc1, weight);
                    var rweight = (int)pGetter(mc1);
                    if (weight != rweight)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("****** PropertyReflectTest() test failed");
                    throw;
                }

            }

            {
                var fGetter = PropertyReflector<MyClass, string>.GetFieldGetterFunc("Name");
                var fSetter = PropertyReflector<MyClass, string>.GetFieldSetterFunc("Name");

                var pGetter = PropertyReflector<MyClass, int>.GetPropertyGetterFunc("Weight");
                var pSetter = PropertyReflector<MyClass, int>.GetPropertySetterFunc("Weight");

                try
                {
                    var mc1 = new MyClass();

                    var name = "Chris";
                    fSetter(mc1, name);
                    var rname = fGetter(mc1);
                    if (name != rname)
                    {
                        throw new Exception();
                    }

                    var weight = 62;
                    pSetter(mc1, weight);
                    var rweight = pGetter(mc1);
                    if (weight != rweight)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("****** PropertyReflectTest() generic test failed");
                    throw;
                }

            }
        }
Ejemplo n.º 7
0
 public static void SetName(MyClass obj, string name)
 {
     obj.Name = name;
 }
Ejemplo n.º 8
0
 public static void SetAge(MyClass obj, int age)
 {
     obj.Age = age;
 }