public void PublicMethods()
        {
            var  test = new TestClass();
            Type t    = typeof(TestClass);

            var m = t.GetMethod("BaseOpen");

            Assert.IsNotNull(m);
            var d = DelegateFactory.CreateMethod(m);

            Assert.IsNotNull(d);
            var parameters = new object[] { "Test" };
            var r          = d.Invoke(test, parameters);

            Assert.IsNull(r);

            m = t.GetMethod("PublicOpen1");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);

            m = t.GetMethod("PublicStaticOpen1");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PublicOpen2");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PublicOpenReturn");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);

#if !SILVERLIGHT
            m = t.GetMethod("PublicOpenOut");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);

            m = t.GetMethod("PublicOpenOutReturn");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PublicOpenRef");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PublicOpenRefReturn");
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);
#endif

            m = t.GetMethod("PublicOpenGeneric");
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);

            m = t.GetMethod("PublicOpenReturnGeneric");
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", 1 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
        }
        public void PrivateMethods()
        {
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;

            var  test = new TestClass();
            Type t    = typeof(TestClass);

            var m = t.GetMethod("PrivateOpen1", flags);

            Assert.IsNotNull(m);
            var d = DelegateFactory.CreateMethod(m);

            Assert.IsNotNull(d);
            var parameters = new object[] { "Test" };
            var r          = d.Invoke(test, parameters);

            Assert.IsNull(r);

            m = t.GetMethod("PrivateStaticOpen1", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PrivateOpen2", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);


            m = t.GetMethod("PrivateOpenReturn", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", 2 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);

#if !SILVERLIGHT
            m = t.GetMethod("PrivateOpenOut", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "Test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PrivateOpenOutReturn", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", null };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PrivateOpenRef", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);
            Assert.AreEqual("1234", parameters[1]);


            m = t.GetMethod("PrivateOpenRefReturn", flags);
            Assert.IsNotNull(m);
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", "" };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
            Assert.AreEqual("1234", parameters[1]);
#endif

            m = t.GetMethod("PrivateOpenGeneric", flags);
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test" };
            r          = d.Invoke(test, parameters);
            Assert.IsNull(r);

            m = t.GetMethod("PrivateOpenReturnGeneric", flags);
            Assert.IsNotNull(m);
            m = m.MakeGenericMethod(typeof(string));
            d = DelegateFactory.CreateMethod(m);
            Assert.IsNotNull(d);
            parameters = new object[] { "test", 1 };
            r          = d.Invoke(test, parameters);
            Assert.IsNotNull(r);
        }
        public void CreateSetProperty()
        {
            var       testClass  = new TestClass();
            var       properties = typeof(TestClass).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
            Stopwatch watch      = Stopwatch.StartNew();

            foreach (var propertyInfo in properties)
            {
                var d = DelegateFactory.CreateSet(propertyInfo);
                Assert.IsNotNull(d);

                object value = null;
                switch (propertyInfo.Name)
                {
                case "LastName":
                    value = "Doe";
                    break;

                case "Age":
                    value = 21;
                    break;

                case "PrivateSet":
                    value = "Private Set";
                    break;

                case "PrivateGet":
                    value = "Private Get";
                    break;

                case "Internal":
                    value = "test";
                    break;

                case "IsStatic":
                    value = true;
                    break;

                case "StaticName":
                    value = "CreateSetProperty";
                    break;

                case "FirstName":
                    value = "John";
                    break;
                }

                d(testClass, value);
                Console.WriteLine("Property: {0} Value: {1}", propertyInfo.Name, value);
            }
            watch.Stop();
            Console.WriteLine("Time: {0}ms", watch.ElapsedMilliseconds);

            Assert.AreEqual("Doe", testClass.LastName);
            Assert.AreEqual(21, testClass.Age);
            Assert.AreEqual("Private Set", testClass.PrivateSet);
            Assert.AreEqual("test", testClass.Internal);
            Assert.AreEqual(true, TestClass.IsStatic);
            Assert.AreEqual("CreateSetProperty", TestClass.StaticName);
            Assert.AreEqual("John", testClass.FirstName);
        }