public void TestOnClick() { //testing to see how long it takes to generate all the getter/setter delegates object transformobj = room.defaultNode.body; dynamic nodedynamic = room.defaultNode; List<Func<Node, float>> delList = new List<Func<Node, float>>(); //float total = 0; Movement movement = new Movement(); //redirector.TargetObject = movement; //redirector.PropertyToObject["active"] = movement; redirector.AssignObjectToPropertiesAll(movement); PropertyInfo pinfo = movement.GetType().GetProperty("active"); //Action<object, object> movementsetter = redirector.setters[typeof(Movement)]["active"]; //Console.WriteLine(":::" + movement.active); //bool a = redirector.active; //bool a = false; OldStartTimer(); for (int i = 0; i < 100000; i++) { //if (i > 0) if (i > 1) if (i > 2) if (i > 3) if (i > 4) total++; //delList.Add(getDel); //float slow = (float)minfo.Invoke((Transform)transformobj, new object[] { }); //float mass = getDel(room.defaultNode); //float mass2 = getDel((Transform)transformobj); //doesn't work because it's of type Object at compile time //float mass2 = getDel(nodedynamic); //total += mass; //gotten = room.defaultNode.GetComponent<Movement>(); //generic method to grab components //gotten = room.defaultNode.comps[comp.movement]; //bool act = gotten.active; //gotten.active = true; redirector.active = false; //21m(impossible)... 24m(new) ... 19m (newer) ... 16m(newest) //a = redirector.active; //pinfo.SetValue(movement, false, null); //34m //movementsetter(movement, false); //4m(old)......... 6m(new) //movement.active = false; } //Movement move = room.defaultNode.comps[comp.movement]; OldStopTimer(); //Console.WriteLine(total); /* //this code won't run right now, but it represents the ability to make a specific generic method based on type variables from another generic method, and then invoke it... (this is slow) MethodInfo method = GetType().GetMethod("DoesEntityExist") .MakeGenericMethod(new Type[] { typeof(Type) }); method.Invoke(this, new object[] { dt, mill }); */ //gotten.fallOff(); ///////////////////////////////////////////////////////////////////////////// }
public void TestRedirect() { Movement move = new Movement(); Collision col = new Collision(); Node nod = new Node(OrbIt.game.room); move.active = true; col.active = true; nod.active = true; Console.WriteLine(move.active + " " + col.active + " " + nod.active); redirector.AssignObjectToPropertySet("active", move); redirector.active = false; redirector.AssignObjectToPropertySet("active", col); redirector.active = false; redirector.AssignObjectToPropertySet("active", nod); redirector.active = false; Console.WriteLine(move.active + " " + col.active + " " + nod.active); }
public void OldTests() { ////////////////////////////////////////////////////////////////////////////////////// List<int> ints = new List<int> { 1, 2, 3 }; ints.ForEach(delegate(int i) { if (i == 2) ints.Remove(i); }); //COOL: NO ENUMERATION WAS MODIFIED ERROR ints.ForEach(delegate(int i) { Console.WriteLine(i); }); MethodInfo testmethod = room.GetType().GetMethod("test"); Action<Room, int, float, string> del = (Action<Room, int, float, string>)Delegate.CreateDelegate(typeof(Action<Room, int, float, string>), testmethod); del(room, 1, 0.3f, "Action worked."); Action<int, float, string> del2 = (Action<int, float, string>)Delegate.CreateDelegate(typeof(Action<int, float, string>), room, testmethod); //target is bound to 'room' in this example due to the overload of CreateDelegate used. del2(2, 3.3f, "Action worked again."); PropertyInfo pinfo = typeof(Component).GetProperty("active"); MethodInfo minfo = pinfo.GetGetMethod(); Console.WriteLine("{0}", minfo.ReturnType); Movement tester = new Movement(); tester.active = true; bool ret = (bool)minfo.Invoke(tester, new object[] { }); //VERY expensive (slow) Console.WriteLine("{0}", ret); Func<Component, bool> delGet = (Func<Component, bool>)Delegate.CreateDelegate(typeof(Func<Component, bool>), minfo); Console.WriteLine("{0}", delGet(tester)); //very fast, and no cast or creation of empty args array required minfo = pinfo.GetSetMethod(); //Console.WriteLine("{0} {1}", minfo.ReturnType, minfo.GetParameters()[0].ParameterType); Action<Component, bool> delSet = (Action<Component, bool>)Delegate.CreateDelegate(typeof(Action<Component, bool>), minfo); delSet(tester, false); Console.WriteLine("Here we go: {0}", delGet(tester)); delSet(tester, true); ///////////////////////////////////////////////////////////////////////////////////////// /* //gets all types that are a subclass of Component List<Type> types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .Where(type => type.IsSubclassOf(typeof(Component))).ToList(); foreach (Type t in types) Console.WriteLine(t); */ //room.defaultNode.Update(new GameTime()); //for testing //MODIFIER ADDITION /* room.defaultNode.addComponent(comp.modifier, true); //room.defaultNode.comps[comp.modifier].active = false; ModifierInfo modinfo = new ModifierInfo(); modinfo.AddFPInfoFromString("o1", "scale", room.defaultNode); modinfo.AddFPInfoFromString("m1", "position", room.defaultNode); modinfo.AddFPInfoFromString("v1", "position", room.defaultNode); modinfo.args.Add("mod", 4.0f); modinfo.args.Add("times", 3.0f); modinfo.args.Add("test", 3.0f); //modinfo.delegateName = "Mod"; //modinfo.delegateName = "Triangle"; //modinfo.delegateName = "VelocityToOutput"; //modinfo.delegateName = "VectorSine"; modinfo.delegateName = "VectorSineComposite"; room.defaultNode.comps[comp.modifier].modifierInfos["sinecomposite"] = modinfo; */ ObservableHashSet<int> obints = new ObservableHashSet<int>(); obints.CollectionChanged += (s, e) => { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { foreach (int i in e.NewItems) { Console.WriteLine("Added:" + i); } } }; obints.Add(6); }