本文整理汇总了C#中Tracker.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Tracker.Clear方法的具体用法?C# Tracker.Clear怎么用?C# Tracker.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tracker
的用法示例。
在下文中一共展示了Tracker.Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Combine
public static void Combine()
{
Tracker t1 = new Tracker();
D a = new D(t1.A);
D b = new D(t1.B);
D c = new D(t1.C);
D d = new D(t1.D);
D nothing = (D)(Delegate.Combine());
Assert.Null(nothing);
D one = (D)(Delegate.Combine(a));
t1.Clear();
one(5);
Assert.Equal(t1.S, "A5");
CheckInvokeList(new D[] { a }, one, t1);
D ab = (D)(Delegate.Combine(a, b));
t1.Clear();
ab(5);
Assert.Equal(t1.S, "A5B5");
CheckInvokeList(new D[] { a, b }, ab, t1);
D abc = (D)(Delegate.Combine(a, b, c));
t1.Clear();
abc(5);
Assert.Equal(t1.S, "A5B5C5");
CheckInvokeList(new D[] { a, b, c }, abc, t1);
D abcdabc = (D)(Delegate.Combine(abc, d, abc));
t1.Clear();
abcdabc(9);
Assert.Equal(t1.S, "A9B9C9D9A9B9C9");
CheckInvokeList(new D[] { a, b, c, d, a, b, c }, abcdabc, t1);
}
示例2: CheckIsSingletonDelegate
private static void CheckIsSingletonDelegate(D expected, D actual, Tracker target)
{
Assert.True(expected.Equals(actual));
Delegate[] invokeList = actual.GetInvocationList();
Assert.Equal(invokeList.Length, 1);
bool b = actual.Equals(invokeList[0]);
Assert.True(b);
target.Clear();
expected(9);
String sExpected = target.S;
target.Clear();
actual(9);
String sActual = target.S;
Assert.Equal(sExpected, sActual);
Assert.True(Object.ReferenceEquals(target, actual.Target));
}
示例3: TestRemove
public static void TestRemove()
{
Tracker t1 = new Tracker();
D a = new D(t1.A);
D b = new D(t1.B);
D c = new D(t1.C);
D d = new D(t1.D);
D e = new D(t1.E);
D abc = (D)(Delegate.Combine(a, b, c));
D abcdabc = (D)(Delegate.Combine(abc, d, abc));
D ab = (D)(Delegate.Combine(a, b));
D dab = (D)(Delegate.Combine(d, ab));
D abcc = (D)(Delegate.Remove(abcdabc, dab));
t1.Clear();
abcc(9);
String s = t1.S;
Assert.Equal(s, "A9B9C9C9");
CheckInvokeList(new D[] { a, b, c, c }, abcc, t1);
// Pattern-match is based on structural equivalence, not reference equality.
D acopy = new D(t1.A);
D bbba = (D)(Delegate.Combine(b, b, b, acopy));
D bbb = (D)(Delegate.Remove(bbba, a));
t1.Clear();
bbb(9);
Assert.Equal(t1.S, "B9B9B9");
CheckInvokeList(new D[] { b, b, b }, bbb, t1);
// In the case of multiple occurrences, Remove() must remove the last one.
D abcd = (D)(Delegate.Remove(abcdabc, abc));
t1.Clear();
abcd(9);
Assert.Equal(t1.S, "A9B9C9D9");
CheckInvokeList(new D[] { a, b, c, d }, abcd, t1);
D d1 = (D)(Delegate.RemoveAll(abcdabc, abc));
t1.Clear();
d1(9);
s = t1.S;
Assert.Equal(t1.S, "D9");
CheckInvokeList(new D[] { d }, d1, t1);
D nothing = (D)(Delegate.Remove(d1, d1));
Assert.Null(nothing);
// The pattern-not-found case.
D abcd1 = (D)(Delegate.Remove(abcd, null));
t1.Clear();
abcd1(9);
Assert.Equal(t1.S, "A9B9C9D9");
CheckInvokeList(new D[] { a, b, c, d }, abcd1, t1);
// The pattern-not-found case.
D abcd2 = (D)(Delegate.Remove(abcd, e));
t1.Clear();
abcd2(9);
Assert.Equal(t1.S, "A9B9C9D9");
CheckInvokeList(new D[] { a, b, c, d }, abcd2, t1);
// The pattern-not-found case.
D abcd3 = (D)(Delegate.RemoveAll(abcd, null));
t1.Clear();
abcd3(9);
Assert.Equal(t1.S, "A9B9C9D9");
CheckInvokeList(new D[] { a, b, c, d }, abcd3, t1);
// The pattern-not-found case.
D abcd4 = (D)(Delegate.RemoveAll(abcd, e));
t1.Clear();
abcd4(9);
Assert.Equal(t1.S, "A9B9C9D9");
CheckInvokeList(new D[] { a, b, c, d }, abcd4, t1);
return;
}