Beispiel #1
0
        public void GetMethodInfoFromLambda_StaticGenericOfGenericType()
        {
            using (TT.CreateScope(typeof(TT.TArg1), typeof(int), typeof(TT.TReturn), typeof(string)))
            {
                //-- Arrange

                Expression <Func <TT.TArg1, TT.TArg1, TT.TReturn> > lambda3 = (x, y) => GenericStaticClass <TT.TArg1> .Three <TT.TReturn>(x, y);

                Expression <Func <int, int, string> > lambda3NoTemplate = (x, y) => GenericStaticClass <int> .Three <string>(x, y);

                var expectedMethod3 = typeof(GenericStaticClass <int>)
                                      .GetMethod("Three", BindingFlags.Public | BindingFlags.Static)
                                      .MakeGenericMethod(typeof(string));

                Expression <Func <TT.TArg1, TT.TArg1, TT.TReturn> > lambda4 = (x, y) => GenericStaticClass <TT.TArg1> .Four <TT.TReturn>(x, y);

                Expression <Func <int, int, string> > lambda4NoTemplate = (x, y) => GenericStaticClass <int> .Four <string>(x, y);

                var expectedMethod4 = typeof(GenericStaticClass <int>)
                                      .GetMethod("Four", BindingFlags.Public | BindingFlags.Static)
                                      .MakeGenericMethod(typeof(string));

                //-- Act

                var actualMethod3           = Helpers.ResolveMethodFromLambda(lambda3);
                var actualMethod3NoTemplate = Helpers.ResolveMethodFromLambda(lambda3NoTemplate);

                var actualMethod4           = Helpers.ResolveMethodFromLambda(lambda4);
                var actualMethod4NoTemplate = Helpers.ResolveMethodFromLambda(lambda4NoTemplate);

                //-- Assert

                Assert.That(expectedMethod3, Is.Not.Null);
                Assert.That(actualMethod3, Is.SameAs(expectedMethod3));

                Assert.That(expectedMethod4, Is.Not.Null);
                Assert.That(actualMethod4, Is.SameAs(expectedMethod4));
            }
        }
    public static void Main(string[] args)
    {
        GenericStaticClass <int> .Method(1, 2);

        GenericStaticClass <string> .Method(3, "4");
    }
Beispiel #3
0
        public void GetMethodInfoFromLambda_StaticNonGenericOfGenericType()
        {
            //-- Arrange

            using (TT.CreateScope(typeof(TT.TProperty), typeof(string)))
            {
                Expression <Func <TT.TProperty, TT.TProperty, int> > lambda1 = (x, y) => GenericStaticClass <TT.TProperty> .One(x, y);

                Expression <Func <string, string, int> > lambda1NoTemplate = (x, y) => GenericStaticClass <string> .One(x, y);

                var expectedMethod1 = typeof(GenericStaticClass <string>).GetMethod("One", BindingFlags.Public | BindingFlags.Static);

                Expression <Func <TT.TProperty, TT.TProperty, int> > lambda2 = (x, y) => GenericStaticClass <TT.TProperty> .Two(x, y);

                Expression <Func <string, string, int> > lambda2NoTemplate = (x, y) => GenericStaticClass <string> .Two(x, y);

                var expectedMethod2 = typeof(GenericStaticClass <string>).GetMethod("Two", BindingFlags.Public | BindingFlags.Static);

                //-- Act

                var actualMethod1           = Helpers.ResolveMethodFromLambda(lambda1);
                var actualMethod1NoTemplate = Helpers.ResolveMethodFromLambda(lambda1NoTemplate);

                var actualMethod2           = Helpers.ResolveMethodFromLambda(lambda2);
                var actualMethod2NoTemplate = Helpers.ResolveMethodFromLambda(lambda2NoTemplate);

                //-- Assert

                Assert.That(expectedMethod1, Is.Not.Null);
                Assert.That(actualMethod1, Is.SameAs(expectedMethod1));
                Assert.That(actualMethod1NoTemplate, Is.SameAs(expectedMethod1));

                Assert.That(expectedMethod2, Is.Not.Null);
                Assert.That(actualMethod2, Is.SameAs(expectedMethod2));
                Assert.That(actualMethod2NoTemplate, Is.SameAs(expectedMethod2));
            }
        }