internal static JsDelegateFunction CombineDelegates(JsDelegateFunction del1, JsDelegateFunction del2) { if (del1 == null) return del2; if (del2 == null) return del1; var del = CreateMulticastDelegateFunction(); del.delegates = new JsArray<JsDelegateFunction>(); if (del1.isMulticastDelegate) { for (var i = 0; i < del1.delegates.length; i++) del.delegates.push(del1.delegates[i]); } else { del.delegates.push(del1); } if (del2.isMulticastDelegate) { for (var i = 0; i < del2.delegates.length; i++) del.delegates.push(del2.delegates[i]); } else { del.delegates.push(del2); } return del; }
internal static JsDelegateFunction RemoveDelegate(JsDelegateFunction delOriginal, JsDelegateFunction delToRemove) { if (delToRemove == null || delOriginal == null) { return(delOriginal); } if (delOriginal.isMulticastDelegate) { if (delToRemove.isMulticastDelegate) { throw new NotImplementedException("Multicast to multicast delegate removal is not implemented yet"); } var del = CreateMulticastDelegateFunction(); for (var i = 0; i < delOriginal.delegates.length; i++) { var del2 = delOriginal.delegates[i]; if (del2 != delToRemove) { if (del.delegates == null) { del.delegates = new JsArray <JsDelegateFunction>(); } del.delegates.push(del2); } } if (del.delegates == null) { return(null); } //del.delegates = delOriginal.delegates.splice(0, 0);//clone if (del.delegates.length == 1) { return(del.delegates[0]); } return(del); } else { if (delToRemove.isMulticastDelegate) { throw new NotImplementedException("single to multicast delegate removal is not supported"); } if (delOriginal == delToRemove) { return(null); } return(delOriginal); } }
static JsDelegateFunction CreateMulticastDelegateFunction() { JsDelegateFunction del2 = null; var del = new JsNativeFunc <object>(delegate() { var x = undefined; for (var i = 0; i < del2.delegates.length; i++) { var del3 = del2.delegates[i]; x = del3.apply(null, arguments.As <object[]>()); } return(x); }).As <JsDelegateFunction>(); del.isMulticastDelegate = true; del2 = del; return(del); }
internal static JsDelegateFunction CombineDelegates(JsDelegateFunction del1, JsDelegateFunction del2) { if (del1 == null) { return(del2); } if (del2 == null) { return(del1); } var del = CreateMulticastDelegateFunction(); del.delegates = new JsArray <JsDelegateFunction>(); if (del1.isMulticastDelegate) { for (var i = 0; i < del1.delegates.length; i++) { del.delegates.push(del1.delegates[i]); } } else { del.delegates.push(del1); } if (del2.isMulticastDelegate) { for (var i = 0; i < del2.delegates.length; i++) { del.delegates.push(del2.delegates[i]); } } else { del.delegates.push(del2); } return(del); }
internal static JsDelegateFunction RemoveDelegate(JsDelegateFunction delOriginal, JsDelegateFunction delToRemove) { if (delToRemove == null || delOriginal == null) return delOriginal; if (delOriginal.isMulticastDelegate) { if (delToRemove.isMulticastDelegate) throw new NotImplementedException("Multicast to multicast delegate removal is not implemented yet"); var del = CreateMulticastDelegateFunction(); for (var i = 0; i < delOriginal.delegates.length; i++) { var del2 = delOriginal.delegates[i]; if (del2 != delToRemove) { if (del.delegates == null) del.delegates = new JsArray<JsDelegateFunction>(); del.delegates.push(del2); } } if (del.delegates == null) return null; //del.delegates = delOriginal.delegates.splice(0, 0);//clone if (del.delegates.length == 1) return del.delegates[0]; return del; } else { if (delToRemove.isMulticastDelegate) throw new NotImplementedException("single to multicast delegate removal is not supported"); if (delOriginal == delToRemove) return null; return delOriginal; } }