public void ObjectAsBaseTest() { //TODO: Same for props and events //Better naming // Comments // out and ref params // rewrite test, one big with all features and lots of handlers // Create factory using plain object as base var factory = new AdaptiveFactory <object>(); factory.ImplementMethods(m => m.Name == "Max").UsingSharedExecuter(GetMaxHandler); factory.ImplementMethods().UsingSharedExecuter(InitObjectAsBase, ExecObjectAsBase); factory.ImplementProperties(p => p.PropertyType == typeof(int)).UsingGetterAndSetter(InitProp, GetIntProp, SetIntProp); factory.ImplementEvents().UsingAdderAndRemover(InitEvent, AddEvent, RemoveEvent); //factory.AddMethodHandler<string>().ForAllMethods().WithInitializer(InitObjectAsBase).WithExecutor(ExecObjectAsBase); // Create implementation Type type = factory.Implement(typeof(ILayer)); Assert.AreEqual(typeof(object), type.BaseType); Assert.AreNotEqual(typeof(object), type); // Verify same implementation next time Assert.AreSame(type, factory.Implement(typeof(ILayer))); // Create instance and call it ILayer layer = (ILayer)Activator.CreateInstance(type); Assert.AreEqual(3, layer.Add(1, 2)); Assert.AreEqual(30, layer.Add(10, 20)); var d = layer.GetOnly; layer.GetAndSet = 22; layer.Fire += layer_Fire; layer.Fire -= layer_Fire; // TODO: Impl setter, check box/unbox scenarios, generic setter/getter, generic TInfo int max = layer.Max(1, 3, 2); Assert.AreEqual(3, max); }
static TestAccessLayer() { s_Factory = new AdaptiveFactory <TestAccessLayer>(); // Method handlers s_Factory.ImplementMethods(m => m.Name == "A").UsingSharedExecuter(InitA, ExecA); s_Factory.ImplementMethods(m => m.Name == "B").UsingSharedExecuter(InitB, ExecB); s_Factory.ImplementMethods(m => m.Name == "C").UsingSharedExecuter("InitC", "ExecC"); // Property handlers s_Factory.ImplementProperties(p => p.Name.StartsWith("P")).UsingGetterAndSetter(InitP, GetP, SetP); s_Factory.ImplementProperties(p => p.Name.StartsWith("Q")).UsingGetterAndSetter(InitQ, GetP, SetP); s_Factory.ImplementProperties(p => p.Name.StartsWith("R")) .UsingBackingField() .WithGetInspector(GetInspector) .WithGetInspector("GenericGetInspector") .WithSetInspector("SetInspector", "SetInspector"); // Event handlers s_Factory.ImplementEvents().UsingAdderAndRemover("InitEvent", "AddEvent", "RemoveEvent"); // TODO: State without initializer, generic getter/setter, setter does not work, split getter/setter }