Ejemplo n.º 1
0
        public void CreateTryGetValueDelegateWrapsGenericObjectDictionaries() {
            // Arrange
            object dictionary = new Dictionary<object, int>(){
                { "theKey", 42 }
            };

            // Act
            TryGetValueDelegate d = TypeHelpers.CreateTryGetValueDelegate(dictionary.GetType());

            object value;
            bool found = d(dictionary, "theKey", out value);

            // Assert
            Assert.IsTrue(found);
            Assert.AreEqual(42, value);
        }
 public void IsGenericInterfaceAssignableFrom_ReturnsFalseOnIsAssignableForUnimplementedInterface()
 {
     Dictionary<int, int> dictionary = new Dictionary<int, int>();
     Assert.Equal(false, typeof(IList<>).IsGenericInterfaceAssignableFrom(dictionary.GetType()));
 }
 public void GetGenericInterfaceTypeParameters_ThrowsOnUnimplementedInterface()
 {
     Dictionary<int, int> dictionary = new Dictionary<int, int>();
     Assert.Throws<ArgumentException>(() => typeof(IList<>).GetGenericInterfaceTypeParameters(dictionary.GetType()));
 }
Ejemplo n.º 4
0
        public void TestCacheableMethodPocoVoidTimed()
        {


            var tValue = new Dictionary<object, object>();

            var tCachedInvoke = new CacheableInvocation(InvocationKind.InvokeMemberAction, "Clear");

            var tWatch = TimeIt.Go(() => tCachedInvoke.Invoke(tValue));
            var tMethodInfo = tValue.GetType().GetMethod("Clear", new Type[] { });
            var tWatch2 = TimeIt.Go(() => tMethodInfo.Invoke(tValue, new object[] { }));

            TestContext.WriteLine("Impromptu: " + tWatch.Elapsed);
            TestContext.WriteLine("Reflection: " + tWatch2.Elapsed);
            TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks);
            Assert.Less(tWatch.Elapsed, tWatch2.Elapsed);
        }