本文整理汇总了C#中System.Collections.Dictionary.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.GetType方法的具体用法?C# Dictionary.GetType怎么用?C# Dictionary.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTryGetValueDelegateWrapsGenericObjectDictionaries
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);
}
示例2: IsGenericInterfaceAssignableFrom_ReturnsFalseOnIsAssignableForUnimplementedInterface
public void IsGenericInterfaceAssignableFrom_ReturnsFalseOnIsAssignableForUnimplementedInterface()
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
Assert.Equal(false, typeof(IList<>).IsGenericInterfaceAssignableFrom(dictionary.GetType()));
}
示例3: GetGenericInterfaceTypeParameters_ThrowsOnUnimplementedInterface
public void GetGenericInterfaceTypeParameters_ThrowsOnUnimplementedInterface()
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
Assert.Throws<ArgumentException>(() => typeof(IList<>).GetGenericInterfaceTypeParameters(dictionary.GetType()));
}
示例4: TestCacheableMethodPocoVoidTimed
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);
}