本文整理汇总了C#中ConditionalWeakTable.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ConditionalWeakTable.GetType方法的具体用法?C# ConditionalWeakTable.GetType怎么用?C# ConditionalWeakTable.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConditionalWeakTable
的用法示例。
在下文中一共展示了ConditionalWeakTable.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clear_AllValuesRemoved
public static void Clear_AllValuesRemoved(int numObjects)
{
var cwt = new ConditionalWeakTable<object, object>();
MethodInfo clear = cwt.GetType().GetMethod("Clear", BindingFlags.NonPublic | BindingFlags.Instance);
if (clear == null)
{
// Couldn't access the Clear method; skip the test.
return;
}
object[] keys = Enumerable.Range(0, numObjects).Select(_ => new object()).ToArray();
object[] values = Enumerable.Range(0, numObjects).Select(_ => new object()).ToArray();
for (int iter = 0; iter < 2; iter++)
{
// Add the objects
for (int i = 0; i < numObjects; i++)
{
cwt.Add(keys[i], values[i]);
Assert.Same(values[i], cwt.GetValue(keys[i], _ => new object()));
}
// Clear the table
clear.Invoke(cwt, null);
// Verify the objects are removed
for (int i = 0; i < numObjects; i++)
{
object ignored;
Assert.False(cwt.TryGetValue(keys[i], out ignored));
}
// Do it a couple of times, to make sure the table is still usable after a clear.
}
}