public virtual void TestGeneral() { Assert.AreEqual(0, PublicTestMethod.GetImplementationDistance(this.GetType())); Assert.AreEqual(1, PublicTestMethod.GetImplementationDistance(typeof(TestClass1))); Assert.AreEqual(1, PublicTestMethod.GetImplementationDistance(typeof(TestClass2))); Assert.AreEqual(3, PublicTestMethod.GetImplementationDistance(typeof(TestClass3))); Assert.IsFalse(PublicTestMethod.IsOverriddenAsOf(typeof(TestClass4))); Assert.IsFalse(PublicTestMethod.IsOverriddenAsOf(typeof(TestClass5))); Assert.AreEqual(0, ProtectedTestMethod.GetImplementationDistance(this.GetType())); Assert.AreEqual(1, ProtectedTestMethod.GetImplementationDistance(typeof(TestClass1))); Assert.AreEqual(2, ProtectedTestMethod.GetImplementationDistance(typeof(TestClass2))); Assert.AreEqual(2, ProtectedTestMethod.GetImplementationDistance(typeof(TestClass3))); Assert.IsFalse(ProtectedTestMethod.IsOverriddenAsOf(typeof(TestClass4))); Assert.IsFalse(ProtectedTestMethod.IsOverriddenAsOf(typeof(TestClass5))); Assert.IsTrue(VirtualMethod <TestVirtualMethod> .compareImplementationDistance(typeof(TestClass3), PublicTestMethod, ProtectedTestMethod) > 0); Assert.AreEqual(0, VirtualMethod <TestVirtualMethod> .compareImplementationDistance(typeof(TestClass5), PublicTestMethod, ProtectedTestMethod)); }
public virtual void TestGeneral() { // LUCENENET: Substituted BaseTestVirtualMethod for this class, but the logic is the same. Assert.AreEqual(0, publicTestMethod.GetImplementationDistance(typeof(BaseTestVirtualMethod))); Assert.AreEqual(1, publicTestMethod.GetImplementationDistance(typeof(TestClass1))); Assert.AreEqual(1, publicTestMethod.GetImplementationDistance(typeof(TestClass2))); Assert.AreEqual(3, publicTestMethod.GetImplementationDistance(typeof(TestClass3))); Assert.IsFalse(publicTestMethod.IsOverriddenAsOf(typeof(TestClass4))); Assert.IsFalse(publicTestMethod.IsOverriddenAsOf(typeof(TestClass5))); // LUCENENET: Substituted BaseTestVirtualMethod for this class, but the logic is the same. Assert.AreEqual(0, protectedTestMethod.GetImplementationDistance(typeof(BaseTestVirtualMethod))); Assert.AreEqual(1, protectedTestMethod.GetImplementationDistance(typeof(TestClass1))); Assert.AreEqual(2, protectedTestMethod.GetImplementationDistance(typeof(TestClass2))); Assert.AreEqual(2, protectedTestMethod.GetImplementationDistance(typeof(TestClass3))); Assert.IsFalse(protectedTestMethod.IsOverriddenAsOf(typeof(TestClass4))); Assert.IsFalse(protectedTestMethod.IsOverriddenAsOf(typeof(TestClass5))); Assert.IsTrue(VirtualMethod.CompareImplementationDistance(typeof(TestClass3), publicTestMethod, protectedTestMethod) > 0); Assert.AreEqual(0, VirtualMethod.CompareImplementationDistance(typeof(TestClass5), publicTestMethod, protectedTestMethod)); }
/// <summary> /// Utility method that compares the implementation/override distance of two methods. </summary> /// <returns> <ul> /// <li>> 1, iff <paramref name="m1"/> is overridden/implemented in a subclass of the class overriding/declaring <paramref name="m2"/> /// <li>< 1, iff <paramref name="m2"/> is overridden in a subclass of the class overriding/declaring <paramref name="m1"/> /// <li>0, iff both methods are overridden in the same class (or are not overridden at all) /// </ul> </returns> public static int CompareImplementationDistance(Type clazz, VirtualMethod m1, VirtualMethod m2) { return(m1.GetImplementationDistance(clazz).CompareTo(m2.GetImplementationDistance(clazz))); }
static TestVirtualMethod() { PublicTestMethod = new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod), "PublicTest", typeof(string)); ProtectedTestMethod = new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod), "ProtectedTest", typeof(int)); }
/// <summary> /// Utility method that compares the implementation/override distance of two methods. </summary> /// <returns> <ul> /// <li>> 1, iff {@code m1} is overridden/implemented in a subclass of the class overriding/declaring {@code m2} /// <li>< 1, iff {@code m2} is overridden in a subclass of the class overriding/declaring {@code m1} /// <li>0, iff both methods are overridden in the same class (or are not overridden at all) /// </ul> </returns> public static int CompareImplementationDistance(Type clazz, VirtualMethod m1, VirtualMethod m2) { return Convert.ToInt32(m1.GetImplementationDistance(clazz)).CompareTo(m2.GetImplementationDistance(clazz)); }
static TestVirtualMethod() { PublicTestMethod = new VirtualMethod <TestVirtualMethod>(typeof(TestVirtualMethod), "PublicTest", typeof(string)); ProtectedTestMethod = new VirtualMethod <TestVirtualMethod>(typeof(TestVirtualMethod), "ProtectedTest", typeof(int)); }
/// <summary> /// Utility method that compares the implementation/override distance of two methods. </summary> /// <returns> <ul> /// <li>> 1, iff {@code m1} is overridden/implemented in a subclass of the class overriding/declaring {@code m2} /// <li>< 1, iff {@code m2} is overridden in a subclass of the class overriding/declaring {@code m1} /// <li>0, iff both methods are overridden in the same class (or are not overridden at all) /// </ul> </returns> public static int compareImplementationDistance <C>(Type clazz, VirtualMethod <C> m1, VirtualMethod <C> m2) { return(Convert.ToInt32(m1.GetImplementationDistance(clazz)).CompareTo(m2.GetImplementationDistance(clazz))); }