public static void AddMessageHandler(uint wmCode, ActionRef<Message> messageHandler) { if (m_messageDictionary.ContainsKey(wmCode)) m_messageDictionary[wmCode] += messageHandler; else m_messageDictionary.Add(wmCode, messageHandler); }
public BindingNode(BindingNode <InputType, OutputType> other) { valueGetter = other.valueGetter; valueSetter = other.valueSetter; ManagingScope = other.ManagingScope; capsuledObject = other.capsuledObject; }
public void RefMethodCallingRefMethod() { void CallOtherRef(ref int localByRef) => SetMinus1(ref localByRef); var objRef = Parameter(typeof(int).MakeByRefType()); var variable = Variable(typeof(int)); var call = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(SetMinus1)); var lambda = Lambda <ActionRef <int> >(Call(call, objRef), objRef); var compiledA = lambda.Compile(); var exampleA = default(int); compiledA(ref exampleA); Assert.AreEqual(-1, exampleA); var compiledB = lambda.CompileFast <ActionRef <int> >(true); var exampleB = default(int); compiledB(ref exampleB); Assert.AreEqual(-1, exampleB); ActionRef <int> direct = CallOtherRef; var exampleC = default(int); direct(ref exampleC); Assert.AreEqual(-1, exampleC); }
static public void RegisterUndo <T>(ActionRef <T> action, ref T t, params Object[] objs) { var rs = new List <Object>(); var sr = GetStateRoot(); if (sr != null) { rs.Add(sr); } if (objs != null) { rs.AddRange(objs); } UnityEditor.Undo.RecordObjects(rs.ToArray(), "State Root Change"); for (int i = 0; i < rs.Count; ++i) { UnityEditor.EditorUtility.SetDirty(rs[i]); } action(ref t); for (int i = 0; i < rs.Count; ++i) { UnityEditor.EditorUtility.SetDirty(rs[i]); } }
public static void RemoveMessageHandler(uint wmCode, ActionRef <Message> messageHandler) { if (m_messageDictionary.ContainsKey(wmCode)) { m_messageDictionary[wmCode] -= messageHandler; } }
public void OutRefMethodCallingRefMethodWithLocal() { void SetIntoLocalVariableAndCallOtherRef(ref int localByRef) { var objVal = localByRef; OutSetMinus1(out objVal); } var objRef = Parameter(typeof(int).MakeByRefType()); var variable = Variable(typeof(int)); var call = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(OutSetMinus1)); var lambda = Lambda <ActionRef <int> >(Block(new[] { variable }, Assign(variable, objRef), Call(call, variable)), objRef); var compiledB = lambda.CompileFast <ActionRef <int> >(true); var exampleB = default(int); compiledB(ref exampleB); Assert.AreEqual(0, exampleB); ActionRef <int> direct = SetIntoLocalVariableAndCallOtherRef; var exampleC = default(int); direct(ref exampleC); Assert.AreEqual(0, exampleC); }
static void Main(string[] args) { var nums = new List <int> { 1, 2, 3, 4 }; //var funcs = new List<> { Add, Mult, Sub }; // what do we put inside the <>? //MathFunc addFunc = Add; // assign add to MathFunc //Console.WriteLine(Add(5,6)); //Console.WriteLine(addFunc(2,3)); //MathFunc divideFunc = (int x, int y) => x / y; //Console.WriteLine(divideFunc(12,6)); // Actions return type is void, input is ranging from 0 params to 16 params int x = 5; ActionRef foo = (ref int val) => { val += 55; Console.WriteLine(val); }; foo(ref x); Console.WriteLine(x); }
internal Task StartListen(ActionRef <T> waitedDelegate, CancellationToken cancellationToken = default) => Task.Factory.StartNew( () => WaitingFor(Reader, waitedDelegate, cancellationToken), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default );
public void AsValueAndAsRef() { void SetIntoLocalVariableAndCallOtherRef(ref int localByRef) { AsValueAndSetMinusOneAsRefCall(localByRef, ref localByRef); } var objRef = Parameter(typeof(int).MakeByRefType()); var call = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(AsValueAndSetMinusOneAsRefCall)); var lambda = Lambda <ActionRef <int> >(Call(call, objRef, objRef), objRef); void LocalAssert(ActionRef <int> invoke) { var exampleA = default(int); invoke(ref exampleA); Assert.AreEqual(-1, exampleA); } var compiledB = lambda.CompileFast <ActionRef <int> >(true); LocalAssert(compiledB); ActionRef <int> direct = SetIntoLocalVariableAndCallOtherRef; LocalAssert(direct); }
void LocalAssert(ActionRef <object> invoke) { var obj = default(object); invoke(ref obj); Assert.AreNotEqual(default(object), obj); }
public void RefAssignCustomStruct() { void AddSet(ref BigInteger byRef) { byRef = byRef + new BigInteger(3); } var objRef = Parameter(typeof(BigInteger).MakeByRefType()); var ctor = typeof(BigInteger).GetTypeInfo().DeclaredConstructors .Single(x => x.GetParameters().Count() == 1 && x.GetParameters().FirstOrDefault()?.ParameterType == typeof(int)); var lambda = Lambda <ActionRef <BigInteger> >(Assign(objRef, Add(objRef, New(ctor, Constant(3)))), objRef); void LocalAssert(ActionRef <BigInteger> invoke) { BigInteger exampleA = 5; invoke(ref exampleA); Assert.AreEqual(new BigInteger(8), exampleA); } var compiledB = lambda.CompileFast <ActionRef <BigInteger> >(true); LocalAssert(compiledB); ActionRef <BigInteger> direct = AddSet; LocalAssert(direct); }
public void RefDoNothingShouldNoCrashCustomStruct() { void DoNothing(ref BigInteger ignore) { }; var lambda = Lambda <ActionRef <BigInteger> >(Empty(), Parameter(typeof(BigInteger).MakeByRefType())); void LocalAssert(ActionRef <BigInteger> invoke) { var exampleA = default(BigInteger); invoke(ref exampleA); Assert.AreEqual(new BigInteger(0), exampleA); } var compiledA = lambda.Compile(); LocalAssert(compiledA); var compiledB = lambda.CompileFast <ActionRef <BigInteger> >(true); LocalAssert(compiledB); ActionRef <BigInteger> direct = DoNothing; LocalAssert(direct); }
string FormatEnum(ref tag_field field, List <string> options, Type baseType, ActionRef <int> incrementMethod, bool isFlags = false) { StringWriter stringWriter = new StringWriter(); Dictionary <string, int> optionDictionary = new Dictionary <string, int>(); var baseTypeString = FormatTypeReference(baseType); if (isFlags) { stringWriter.WriteLine("[Flags]"); } stringWriter.WriteLine(string.Format("public enum {0} : {1}", ToTypeName(field.Name), baseTypeString)); stringWriter.WriteLine('{'); var index = isFlags ? 1 : 0; foreach (string option in options) { if (option != string.Empty) { stringWriter.WriteLine("{0} = {1},", ProcessFieldName(ToTypeName(option), optionDictionary), index); } incrementMethod(ref index); } stringWriter.WriteLine("}"); return(stringWriter.ToString()); }
public void RefFromConstant() { void SetSmallConstant(ref int localByRef) { const int objVal = 3; localByRef = objVal; } var objRef = Parameter(typeof(int).MakeByRefType()); var lambda = Lambda <ActionRef <int> >(Assign(objRef, Constant(3)), objRef); var compiledA = lambda.Compile(); var exampleA = default(int); compiledA(ref exampleA); Assert.AreEqual(3, exampleA); var compiledB = lambda.CompileFast <ActionRef <int> >(true); var exampleB = default(int); compiledB(ref exampleB); Assert.AreEqual(3, exampleB); ActionRef <int> direct = SetSmallConstant; var exampleC = default(int); direct(ref exampleC); Assert.AreEqual(3, exampleC); }
public void RefReturnToVoid() { ushort SetSmallConstant(ref uint localByRef) { localByRef = 3; return(7); } var objRef = Parameter(typeof(uint).MakeByRefType()); var lambda = Lambda <ActionRef <uint> >(Block(Assign(objRef, Constant((uint)3)), Constant((ushort)7)), objRef); var compiledA = lambda.Compile(); var exampleA = default(uint); compiledA(ref exampleA); Assert.AreEqual(3, exampleA); var compiledB = lambda.CompileFast <ActionRef <uint> >(true); var exampleB = default(uint); compiledB(ref exampleB); Assert.AreEqual(3, exampleB); ActionRef <uint> direct = (ref uint x) => SetSmallConstant(ref x); var exampleC = default(uint); direct(ref exampleC); Assert.AreEqual(3, exampleC); }
public void BlockWithNonRefStatementLast() { void SetSmallConstant(ref uint localByRef) { localByRef = 3; var x = 0.0; } var objRef = Parameter(typeof(uint).MakeByRefType()); var variable = Variable(typeof(double)); var lambda = Lambda <ActionRef <uint> >(Block(new[] { variable }, Assign(objRef, Constant((uint)3)), Assign(variable, Constant(0.0))), objRef); var compiledA = lambda.Compile(); var exampleA = default(uint); compiledA(ref exampleA); Assert.AreEqual(3, exampleA); var compiledB = lambda.CompileFast <ActionRef <uint> >(true); var exampleB = default(uint); compiledB(ref exampleB); Assert.AreEqual(3, exampleB); ActionRef <uint> direct = SetSmallConstant; var exampleC = default(uint); direct(ref exampleC); Assert.AreEqual(3, exampleC); }
public void RefDoNothingShouldNoCrash() { void DoNothing(ref int ignore) { }; var lambda = Lambda <ActionRef <int> >(Empty(), Parameter(typeof(int).MakeByRefType())); void LocalAssert(ActionRef <int> invoke) { var exampleA = default(int); invoke(ref exampleA); Assert.AreEqual(0, exampleA); } var compiledA = lambda.Compile(); LocalAssert(compiledA); var compiledB = lambda.CompileFast <ActionRef <int> >(true); LocalAssert(compiledB); ActionRef <int> direct = DoNothing; LocalAssert(direct); }
public void RefMethodCallingRefMethodCustomStuct() { void CallOtherRef(ref BigInteger localByRef) => SetMinusBigInteger1(ref localByRef); var objRef = Parameter(typeof(BigInteger).MakeByRefType()); var variable = Variable(typeof(BigInteger)); var call = typeof(Issue55_CompileFast_crash_with_ref_parameter).GetTypeInfo().DeclaredMethods.First(m => m.Name == nameof(SetMinusBigInteger1)); var lambda = Lambda <ActionRef <BigInteger> >(Call(call, objRef), objRef); void LocalAssert(ActionRef <BigInteger> invoke) { var exampleA = default(BigInteger); invoke(ref exampleA); Assert.AreEqual(new BigInteger(-1), exampleA); } var compiledB = lambda.CompileFast <ActionRef <BigInteger> >(true); LocalAssert(compiledB); ActionRef <BigInteger> direct = CallOtherRef; LocalAssert(direct); }
public void RefAssign() { void AddSet(ref double byRef) { byRef = byRef + 3.0; } var objRef = Parameter(typeof(double).MakeByRefType()); var lambda = Lambda <ActionRef <double> >(Assign(objRef, Add(objRef, Constant(3.0))), objRef); void LocalAssert(ActionRef <double> invoke) { var exampleA = 5.0; invoke(ref exampleA); Assert.AreEqual(8.0, exampleA); } var compiledB = lambda.CompileFast <ActionRef <double> >(true); LocalAssert(compiledB); ActionRef <double> direct = AddSet; LocalAssert(direct); }
public void ExecuteOnEntityView(int entityGidEntityId, ActionRef <TValue> action) { uint findIndex; if (FindIndex(entityGidEntityId, out findIndex)) { action(ref _values[findIndex]); } }
public static ActionWindow ShowWindow(object startValue, ActionRef <object> onGUI) { ActionWindow window = GetWindow(typeof(ActionWindow), true) as ActionWindow; window.variable = startValue; window.onGUI = onGUI; window.Init(); return(window); }
public void ExecuteOnEntityView <W>(int entityGidEntityId, ref W value, ActionRef <TValue, W> action) { uint findIndex; if (FindIndex(entityGidEntityId, out findIndex)) { action(ref _values[findIndex], ref value); } }
public void ExecuteOnEntities <T>(int groupID, ActionRef <T> action) where T : IEntityStruct { int count; var entities = QueryEntities <T>(groupID, out count); for (int i = 0; i < count; i++) { action(ref entities[i]); } }
private static void ProcessMessage(ref Message message) { ActionRef <Message> output = null; m_messageDictionary.TryGetValue((uint)message.Msg, out output); if (output != null) { output(ref message); } }
private async Task WaitingFor(ChannelReader <T> channelReader, ActionRef <T> waitedDelegate, CancellationToken cancellationToken) { while (await channelReader.WaitToReadAsync(cancellationToken)) { if (channelReader.TryRead(out var waitedObject)) { waitedDelegate(waitedObject); } } }
public void ExecuteOnEntities <T, W>(ref W value, ActionRef <T, W> action) where T : IEntityStruct { int count; var entities = QueryEntities <T>(out count); for (int i = 0; i < count; i++) { action(ref entities[i], ref value); } }
public void RemoveListener(ActionRef listener) { int index = delegates.IndexOf(listener); if (index >= 0) { priorities.RemoveAt(index); delegates.RemoveAt(index); } }
public void Operate(ActionRef <T> optr, int startindex, int endindex) { // Splay segment SelectSegment(startindex, endindex + 2); // Set flag Root.RightChild.LeftChild._operations += optr; // Update Splay(Root.RightChild.LeftChild); }
public static void AddMessageHandler(uint wmCode, ActionRef <Message> messageHandler) { if (m_messageDictionary.ContainsKey(wmCode)) { m_messageDictionary[wmCode] += messageHandler; } else { m_messageDictionary.Add(wmCode, messageHandler); } }
public static ActionPopupWindow ShowWindow(Rect rect, object startValue, ActionRef <object> onGUI, float width = 250, float height = 100) { ActionPopupWindow window = CreateInstance(typeof(ActionPopupWindow)) as ActionPopupWindow; window.variable = startValue; window.onGUI = onGUI; window.width = width; window.height = height; window.Init(rect); return(window); }
public void AddListener(int priority, ActionRef listener) { int index = priorities.BinarySearch(priority, comp); if (index < 0) { index = ~index; } priorities.Insert(index, priority); delegates.Insert(index, listener); }
public static void RemoveMessageHandler(WinApi.WM wmCode, ActionRef<Message> messageHandler) { RemoveMessageHandler((uint)wmCode, messageHandler); }
private string FormatEnum(ref tag_field field, List<string> options, Type baseType, ActionRef<int> incrementMethod, bool isFlags = false) { StringWriter stringWriter = new StringWriter(); Dictionary<string, int> optionDictionary = new Dictionary<string, int>(); var baseTypeString = FormatTypeReference(baseType); if (isFlags) stringWriter.WriteLine("[Flags]"); stringWriter.WriteLine(string.Format("public enum {0} : {1}", ToTypeName(field.Name), baseTypeString)); stringWriter.WriteLine('{'); var index = isFlags ? 1 : 0; foreach (string option in options) { if (option != string.Empty) { stringWriter.WriteLine("{0} = {1},", ProcessFieldName(ToTypeName(option), optionDictionary), index); } incrementMethod(ref index); } stringWriter.WriteLine("}"); return stringWriter.ToString(); }
public static void RemoveMessageHandler(uint wmCode, ActionRef<Message> messageHandler) { if (m_messageDictionary.ContainsKey(wmCode)) m_messageDictionary[wmCode] -= messageHandler; }
private void WriteEnumElement(XmlWriter writer, ref tag_field field, int fieldOffset, List<string> options, Type baseType, ActionRef<int> incrementMethod, bool isFlags = false) { Dictionary<string, int> optionDictionary = new Dictionary<string, int>(); var baseTypeString = FormatEnumReference(baseType, isFlags); string name, description; SplitNameDescription(field.Name, out name, out description); writer.WriteStartElement(baseTypeString); writer.WriteAttributeString("name", Format(name)); if (!string.IsNullOrEmpty(description)) writer.WriteAttributeString("description", description); writer.WriteAttributeString("offset", fieldOffset.ToString()); var index = isFlags ? 0 : 0; foreach (string option in options) { if (option != string.Empty) { SplitNameDescription(option, out name, out description); writer.WriteStartElement("option"); writer.WriteAttributeString("name", Format(name)); if (!string.IsNullOrEmpty(description)) writer.WriteAttributeString("description", description); writer.WriteAttributeString("value", index.ToString()); writer.WriteEndElement(); } incrementMethod(ref index); } writer.WriteEndElement(); }