예제 #1
0
        public void GetMethodInfoFromLambda_StaticNonGenericOfNonGenericType()
        {
            //-- Arrange

            Expression <Func <int, string, string> > lambda = (x, y) => NonGenericStaticClass.One(x, y);
            var expectedMethod = typeof(NonGenericStaticClass).GetMethod("One", BindingFlags.Static | BindingFlags.Public);

            //-- Act

            var actualMethod = Helpers.ResolveMethodFromLambda(lambda);

            //-- Assert

            Assert.That(expectedMethod, Is.Not.Null);
            Assert.That(actualMethod, Is.SameAs(expectedMethod));
        }
예제 #2
0
        public void MethodStaticNonGenericTest()
        {
            #if !NET5_0
            return;
            #endif
            MethodInfo method = Utils.GetMethod(typeof(NonGenericStaticClass), nameof(NonGenericStaticClass.NonGeneric));

            NonGenericStaticClass.NonGeneric();

            MethodHelper.ForceRecompile(method);

            NonGenericStaticClass.NonGeneric();

            int count = MethodsCompiled.ToList().Count(m => m == method);

            Assert.Equal(2, count);
        }
예제 #3
0
        public void GetMethodInfoFromLambda_StaticGenericOfNonGenericType()
        {
            //-- Arrange

            using (TT.CreateScope(typeof(TT.TIndex1), typeof(int), typeof(TT.TIndex2), typeof(string)))
            {
                Expression <Func <TT.TIndex1, TT.TIndex1, TT.TIndex2> > lambda = (x, y) => NonGenericStaticClass.Two <TT.TIndex1, TT.TIndex2>(x, y);
                Expression <Func <int, int, string> > lambdaNoTemplate         = (x, y) => NonGenericStaticClass.Two <int, string>(x, y);

                var expectedMethod = typeof(NonGenericStaticClass)
                                     .GetMethod("Two", BindingFlags.Public | BindingFlags.Static)
                                     .MakeGenericMethod(typeof(int), typeof(string));

                //-- Act

                var actualMethod           = Helpers.ResolveMethodFromLambda(lambda);
                var actualMethodNoTemplate = Helpers.ResolveMethodFromLambda(lambdaNoTemplate);

                //-- Assert

                Assert.That(expectedMethod, Is.Not.Null);
                Assert.That(actualMethod, Is.SameAs(expectedMethod));
                Assert.That(actualMethodNoTemplate, Is.SameAs(expectedMethod));
            }
        }