public void FrTypesAreCached() { var manager = new frManager(); frType myDerivedType = manager.Get(typeof(MyDerivedType)); Assert.IsTrue(ReferenceEquals(myDerivedType, manager.Get(typeof(MyDerivedType)))); Assert.IsTrue(ReferenceEquals(myDerivedType.Parent, manager.Get(typeof(MyBaseType)))); }
public void TestLookupWithNewFields() { var manager = new frManager(); frType myDerivedType = manager.Get(typeof(MyDerivedType)); frType myBaseType = manager.Get(typeof(MyBaseType)); // new fields Assert.AreEqual(typeof(MyDerivedType), myDerivedType.GetDeclaredFieldByName("BaseField").RawMember.DeclaringType); Assert.AreEqual(typeof(MyBaseType), myBaseType.GetDeclaredFieldByName("BaseField").RawMember.DeclaringType); CollectionAssert.AreEquivalent(new[] { myDerivedType.GetDeclaredFieldByName("BaseField"), myBaseType.GetDeclaredFieldByName("BaseField") }, myDerivedType.GetFlattenedFieldsByName("BaseField")); }
public void TestInterfaces() { var manager = new frManager(); frType myBaseType = manager.Get(typeof(MyBaseType)); frType myDerivedType = manager.Get(typeof(MyDerivedType)); CollectionAssert.AreEquivalent(new[] { typeof(IBaseInterface), typeof(IExplicitInterface) }, Interfaces(myBaseType)); CollectionAssert.AreEquivalent(new[] { typeof(IDerivedInterface), typeof(IBaseInterface), typeof(IExplicitInterface) }, Interfaces(myDerivedType)); CallCounts.MyBaseType_MyExplicitMethodCallCount = 0; myBaseType.GetInterface <IExplicitInterface>().GetDeclaredMethodsByName("MyExplicitMethod")[0].Invoke(new MyBaseType(), null); Assert.AreEqual(1, CallCounts.MyBaseType_MyExplicitMethodCallCount); CallCounts.MyDerivedType_MyExplicitMethodCallCount = 0; myDerivedType.GetInterface <IExplicitInterface>().GetDeclaredMethodsByName("MyExplicitMethod")[0].Invoke(new MyDerivedType(), null); Assert.AreEqual(1, CallCounts.MyDerivedType_MyExplicitMethodCallCount); }
public void TestLookupWithOverloadedMethod() { var manager = new frManager(); frType myDerivedType = manager.Get(typeof(MyDerivedType)); frMethod[] methods = myDerivedType.GetDeclaredMethodsByName("ChildMethod"); Assert.IsTrue(methods.Length == 2); Assert.AreEqual(methods[0].RawMethod.Name, methods[1].RawMethod.Name); Assert.AreNotEqual(methods[0], methods[1]); Assert.AreNotEqual(methods[0].RawMethod.GetParameters().Length, methods[1].RawMethod.GetParameters().Length); }
public void Sanity() { var manager = new frManager(); // Verify built in types are supported. Assert.IsNotNull(manager.Get(typeof(object))); Assert.IsNotNull(manager.Get(typeof(int))); // Verify custom types are supported. frType myBaseType = manager.Get(typeof(MyBaseType)); Assert.IsNotNull(myBaseType); // fields/methods on MyTest Assert.AreEqual(typeof(MyBaseType), myBaseType.RawType); CollectionAssert.AreEquivalent(new[] { "BaseField" }, DeclaredFieldNames(myBaseType)); CollectionAssert.AreEquivalent(new[] { "BaseMethod", "BaseVirtualMethod", "FastReflect.IExplicitInterface.MyExplicitMethod" }, DeclaredMethodNames(myBaseType)); // parent type is Object Assert.AreEqual(typeof(object), myBaseType.Parent.RawType); }
public void TestLocalDeclaration() { var manager = new frManager(); frType myDerivedType = manager.Get(typeof(MyDerivedType)); // Verify parent/rawtype Assert.AreEqual(typeof(MyDerivedType), myDerivedType.RawType); Assert.AreEqual(typeof(MyBaseType), myDerivedType.Parent.RawType); // Verify fields/methods // MyDerivedType CollectionAssert.AreEquivalent(new[] { "BaseField", "ChildField" }, DeclaredFieldNames(myDerivedType)); CollectionAssert.AreEquivalent(new[] { "BaseChildMethod", "ChildMethod", "ChildMethod", "FastReflect.IExplicitInterface.MyExplicitMethod" }, DeclaredMethodNames(myDerivedType)); // MyBaseType CollectionAssert.AreEquivalent(new[] { "BaseField" }, DeclaredFieldNames(myDerivedType.Parent)); CollectionAssert.AreEquivalent(new[] { "BaseMethod", "BaseVirtualMethod", "FastReflect.IExplicitInterface.MyExplicitMethod" }, DeclaredMethodNames(myDerivedType.Parent)); }
public void TestAcceleration() { var manager = new frManager(typeof(AccelerationProvider)); frType accelerationType = manager.Get(typeof(AccelerationType)); var instance = new AccelerationType(); instance.Field = 10; CallCounts.Accelerated = 0; accelerationType.GetDeclaredMethodsByName("Method")[0].Invoke(instance, null); Assert.AreEqual(1, CallCounts.Accelerated); CallCounts.Accelerated = 0; Assert.AreEqual(10, accelerationType.GetDeclaredFieldByName("Field").Read <object>(instance)); Assert.AreEqual(1, CallCounts.Accelerated); CallCounts.Accelerated = 0; accelerationType.GetDeclaredFieldByName("Field").Write(ref instance, 20f); Assert.AreEqual(20f, instance.Field); Assert.AreEqual(1, CallCounts.Accelerated); }