コード例 #1
0
        public void Method_ParameterlessInstanceFuncValid()
        {
            ExtendedType et     = typeof(ComplexOverloads <int>);
            Method       method = et.GetMethod("GetOne", typeof(int));

            Assert.IsNotNull(method);
            Func <ComplexOverloads <int>, int> getOne = method.GetFunc(
                typeof(ComplexOverloads <int>),
                typeof(int)) as Func <ComplexOverloads <int>, int>;

            Assert.IsNotNull(getOne);

            ComplexOverloads <int> obj = new ComplexOverloads <int>();

            Assert.AreEqual(1, getOne(obj));
        }
コード例 #2
0
        public void Method_ParameterlessInstanceActionValid()
        {
            ExtendedType et     = typeof(ComplexOverloads <int>);
            Method       method = et.GetMethod("IncrementCounter", typeof(int));

            Assert.IsNotNull(method);
            Action <ComplexOverloads <int> > increment = method.GetAction(
                typeof(ComplexOverloads <int>)) as Action <ComplexOverloads <int> >;

            Assert.IsNotNull(increment);

            ComplexOverloads <int> obj = new ComplexOverloads <int>();
            int original = obj.Counter;

            increment(obj);
            Assert.AreEqual(original + 1, obj.Counter);
        }
コード例 #3
0
        public void Method_InstanceActionValid()
        {
            ExtendedType et     = typeof(ComplexOverloads <int>);
            Method       method = et.GetMethod("IncrementCounter", typeof(int), typeof(void));

            Assert.IsNotNull(method);
            Action <ComplexOverloads <int>, int> increment =
                method.GetAction(typeof(ComplexOverloads <int>), typeof(int)) as Action <ComplexOverloads <int>, int>;

            Assert.IsNotNull(increment);

            ComplexOverloads <int> obj = new ComplexOverloads <int>();
            int original = obj.Counter;
            int a        = Random.Next();

            increment(obj, a);
            Assert.AreEqual(original + a, obj.Counter);
        }
コード例 #4
0
        public void Constructor_FuncConstructorValid()
        {
            ExtendedType et          = typeof(ComplexOverloads <int>);
            Constructor  constructor = et.GetConstructor(typeof(int), typeof(string), typeof(ComplexOverloads <int>));

            Assert.IsNotNull(constructor);
            Func <int, string, ComplexOverloads <int> > constFunc =
                constructor.GetFunc(typeof(int), typeof(string), typeof(ComplexOverloads <int>)) as
                Func <int, string, ComplexOverloads <int> >;

            Assert.IsNotNull(constFunc);
            int    a = Random.Next();
            string s = Random.RandomString();
            ComplexOverloads <int> co = constFunc(a, s);

            Assert.IsNotNull(co);
            Assert.AreEqual(a, co.Value);
            Assert.AreEqual(s, co.Value2);
        }
コード例 #5
0
        public void Method_InstanceFuncValid()
        {
            ExtendedType et     = typeof(ComplexOverloads <int>);
            Method       method = et.GetMethod("Add", typeof(int), typeof(int), typeof(int));

            Assert.IsNotNull(method);
            Func <ComplexOverloads <int>, int, int, int> add = method.GetFunc(
                typeof(ComplexOverloads <int>),
                typeof(int),
                typeof(int),
                typeof(int)) as
                                                               Func <ComplexOverloads <int>, int, int, int>;

            Assert.IsNotNull(add);
            int a = Random.Next();
            int b = Random.Next();

            ComplexOverloads <int> obj = new ComplexOverloads <int>();

            Assert.AreEqual(a + b, add(obj, a, b));
        }