コード例 #1
0
 public void DelayUntilFalse(VoidDelegate function, TDelegate <bool> wait, float time)
 {
     if (function != null && wait != null)
     {
         StartCoroutine(p_DelayUntilFalse(function, wait, time));
     }
 }
コード例 #2
0
 /*
  * void ExecuteUntilFalse(TDelegate<bool> function, float time):
  *      Function: For a bool delegate with no input arguments, it executes that function until the result is "false".
  *      The "time" value shows the frequency by which the function is recalled. If the value is too small, it executes it the next frame.
  *      Usefulness: Easily execute a function in parallel until a function is fulfilled.
  * */
 public void ExecuteUntilFalse(TDelegate <bool> function, float time)
 {
     if (function != null)
     {
         StartCoroutine(p_ExecuteUntilFalse(function, time));
     }
 }
コード例 #3
0
 public void Delay <T, T1, T2, T3, T4> (TDelegate <T, T1, T2, T3, T4> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, float time)
 {
     if (function != null)
     {
         StartCoroutine(p_Delay(function, arg1, arg2, arg3, arg4, time));
     }
 }
コード例 #4
0
 public void Delay <T, T1, T2> (TDelegate <T, T1, T2> function, T1 arg1, T2 arg2, float time)
 {
     if (function != null)
     {
         StartCoroutine(p_Delay(function, arg1, arg2, time));
     }
 }
コード例 #5
0
 private IEnumerator p_ExecuteUntilFalse(TDelegate <bool> function, float time)
 {
     while (function())
     {
         yield return(TimeIE(time));
     }
 }
コード例 #6
0
        /// <inheritdoc />
        public TDelegate GetDelegate(int index = 0)
        {
            IntPtr functionPointer = GetFunctionAddress(index);

            if (functionPointer == _lastFunctionPointer)
            {
                return(_delegate);
            }

            // Try to get the cached function wrapper.
            if (_methodCache.TryGetValue(functionPointer, out var cachedDelegate))
            {
                return(cachedDelegate);
            }

            if (sizeof(IntPtr) == 4)
            {
                _delegate = X86.Wrapper.Create <TDelegate>(functionPointer.ToUnsigned(), out var wrapperAddress);
            }
            else
            {
                _delegate = X64.Wrapper.Create <TDelegate>(functionPointer.ToUnsigned(), out var wrapperAddress);
            }

            _methodCache[functionPointer] = _delegate;
            _lastFunctionPointer          = functionPointer;

            return(_delegate);
        }
コード例 #7
0
 // make sure class maps are registered before tests run
 static CSharp476Tests()
 {
     TDelegate.RegisterClassMap();
     TExpressionCallingConstructor.RegisterClassMap();
     TExpressionCallingFactoryMethod.RegisterClassMap();
     TExpressionCallingArbitraryCode.RegisterClassMap();
 }
コード例 #8
0
    public static int Main()
    {
        Gen <ClassA>       ga   = new Gen <ClassA> ();
        IntDelegate        id   = ga.getIntDelegate();
        TDelegate <ClassA> tda  = ga.getTDelegate();
        IntDelegate        vid  = ga.getVirtIntDelegate();
        TDelegate <ClassA> stda = ga.getStaticTDelegate();

        if (id(123) != 124)
        {
            return(1);
        }
        if (tda().GetType() != typeof(ClassA[]))
        {
            return(1);
        }
        if (vid(123) != 125)
        {
            return(1);
        }
        if (stda().GetType() != typeof(ClassA[]))
        {
            return(1);
        }

        tda = (TDelegate <ClassA>)Delegate.CreateDelegate(typeof(TDelegate <ClassA>),
                                                          typeof(Gen <ClassA>).GetMethod("staticTFunction"));

        if (tda().GetType() != typeof(ClassA[]))
        {
            return(1);
        }

        return(0);
    }
コード例 #9
0
        /// <summary>
        ///     Concatenates the invocation lists of two delegates.
        /// </summary>
        /// <typeparam name="TDelegate">The type of delegate to combine.</typeparam>
        /// <param name="first">The delegate whose invocation list comes first.</param>
        /// <param name="last">The delegate whose invocation list comes last.</param>
        /// <returns>A new delegate with a weak connection to both <paramref name="first"/> and <paramref name="last"/>. If one is <see langword="null"/> but the other is not, returns a delegate with a weak connection to just that the parameter that is not <see langword="null"/>. If both are <see langword="null"/>, returns <see langword="null"/>.</returns>
        /// <seealso cref="Delegate.Combine(Delegate, Delegate)"/>
        public static TDelegate Combine <[DelegateConstraint] TDelegate>(TDelegate first, TDelegate last) where TDelegate : class
        {
            if (ReferenceEquals(first, null) && ReferenceEquals(last, null))
            {
                return(null);
            }
            Delegate             firstDelegate = first as Delegate;
            Delegate             lastDelegate  = last as Delegate;
            Delegate             finalDelegate = CreateDynamicDelegate(first, last, firstDelegate, lastDelegate);
            WeakDelegateSuragate firstSuragate = null;

            if (firstDelegate != null)
            {
                GetCombinedHolder(firstDelegate.Method, out firstSuragate);
            }
            WeakDelegateSuragate lastSuragate = null;

            if (lastDelegate != null)
            {
                GetCombinedHolder(lastDelegate.Method, out lastSuragate);
            }
            WeakDelegateSuragate finalSuragate = firstSuragate != null ? lastSuragate != null?firstSuragate.Add(lastSuragate) : lastDelegate != null?firstSuragate.Add(firstDelegate) : firstSuragate.Clone() : lastSuragate != null ? firstDelegate != null?lastSuragate.Add(firstDelegate) : lastSuragate.Clone() : firstDelegate != null ? lastDelegate != null ? new WeakDelegateSuragate(firstDelegate, lastDelegate) : new WeakDelegateSuragate(firstDelegate) : new WeakDelegateSuragate(lastDelegate);

            suragates.Add(finalDelegate.Method, new WeakReference <WeakDelegateSuragate>(finalSuragate));
            if (firstDelegate != null && firstDelegate.Target != null)
            {
                weakReference.Add(firstDelegate.Target, finalSuragate);
            }
            if (lastDelegate != null && lastDelegate.Target != null)
            {
                weakReference.Add(lastDelegate.Target, finalSuragate);
            }
            return(finalDelegate as TDelegate);
        }
コード例 #10
0
ファイル: FromEvent.cs プロジェクト: shekky/reactive
            private IDisposable AddHandler(IScheduler self, TDelegate onNext)
            {
                var removeHandler = default(IDisposable);

                try
                {
                    removeHandler = _parent.AddHandler(onNext);
                }
                catch (Exception exception)
                {
                    _subject.OnError(exception);
                    return(Disposable.Empty);
                }

                //
                // We don't propagate the exception to the OnError channel upon Dispose. This is
                // not possible at this stage, because we've already auto-detached in the base
                // class Producer implementation. Even if we would switch the OnError and auto-
                // detach calls, it wouldn't work because the remove handler logic is scheduled
                // on the given scheduler, causing asynchrony. We can't block waiting for the
                // remove handler to run on the scheduler.
                //
                _removeHandler.Disposable = removeHandler;

                return(Disposable.Empty);
            }
コード例 #11
0
 /*
  * void Delay<T, T{...}>(TDelegate<T, T{...}> function, T{...} arg{...}, float time):
  *      Function: For a delegate (up to 4 input arguments), it executes that function a particular time later.
  *      The "time" value is in seconds. If the value is too small, it executes it the next frame.
  *      The arguments of the function must be pust after the Delegate and before the time.
  *      Usefulness: Easily execute any function later in time.
  * */
 public void Delay <T> (TDelegate <T> function, float time)
 {
     if (function != null)
     {
         StartCoroutine(p_Delay(function, time));
     }
 }
コード例 #12
0
ファイル: Sources.cs プロジェクト: xyicheng/akka.net
            public Logic(EventSourceStage <TDelegate, TEventArgs> stage) : base(stage.Shape)
            {
                _stage  = stage;
                _buffer = new LinkedList <TEventArgs>();
                var bufferCapacity = stage._maxBuffer;
                var onEvent        = GetAsyncCallback <TEventArgs>(e =>
                {
                    if (IsAvailable(_stage.Out))
                    {
                        Push(_stage.Out, e);
                    }
                    else
                    {
                        if (_buffer.Count >= bufferCapacity)
                        {
                            _onOverflow(e);
                        }
                        else
                        {
                            Enqueue(e);
                        }
                    }
                });

                _handler    = _stage._conversion(onEvent);
                _onOverflow = SetupOverflowStrategy(stage._overflowStrategy);
                SetHandler(stage.Out, this);
            }
コード例 #13
0
 public void Dispose()
 {
     if (this.handler != null)
     {
         this.parent.removeHandler(this.handler);
         this.handler = default(TDelegate);
     }
 }
コード例 #14
0
ファイル: FromEvent.cs プロジェクト: ufcpp/UniRx
 public void Dispose()
 {
     if (handler != null)
     {
         parent.removeHandler(handler);
         handler = default(TDelegate);
     }
 }
コード例 #15
0
 private IEnumerator p_DelayUntilFalse(VoidDelegate function, TDelegate <bool> wait, float time)
 {
     while (wait())
     {
         yield return(TimeIE(time));
     }
     function();
 }
コード例 #16
0
        public void RemoveListener <TParam>(EventDefineEnum eventID, TDelegate <TParam> eventHandle)
        {
            int index = (int)eventID;

            if (CheckValid(index, eventHandle, true))
            {
                listenerTarget[index].Remove(eventHandle);
            }
        }
コード例 #17
0
        public void AddListener(EventDefineEnum eventID, TDelegate eventHandle)
        {
            int index = (int)eventID;

            if (CheckValid(index, eventHandle))
            {
                listenerTarget[index].Add(eventHandle);
            }
        }
コード例 #18
0
        Task DelegatePostset <TDelegate> () where TDelegate : TestDelegate, new()
        {
            var webView = new UIWebView();

            var del    = new TDelegate();
            var hybrid = webView.AsHybridWebView();

            webView.Delegate = del;
            return(TestLoadCallbacks(webView, hybrid, del, true));
        }
コード例 #19
0
            public bool Register()
            {
                handler = parent.conversion(OnNext);

                try {
                    parent.addHandler(handler);
                } catch (Exception ex) {
                    observer.OnError(ex);
                    return(false);
                }

                return(true);
            }
コード例 #20
0
 public bool Register()
 {
     this.handler = this.parent.conversion(new Action(this.OnNext));
     try
     {
         this.parent.addHandler(this.handler);
     }
     catch (Exception error)
     {
         this.observer.OnError(error);
         return(false);
     }
     return(true);
 }
コード例 #21
0
        public void SendEvent(EventDefineEnum eventID)
        {
            int index = (int)eventID;

            if (index > listenerTarget.Length)
            {
                DebugHelper.LogError("EventDefine Error :" + eventID);
                return;
            }
            for (int i = 0; i < listenerTarget[index].Count; i++)
            {
                TDelegate tempDelegate = listenerTarget[index][i] as TDelegate;
                if (tempDelegate != null)
                {
                    tempDelegate();
                }
            }
        }
コード例 #22
0
        public void SendEvent <TParam>(EventDefineEnum eventID, TParam param)
        {
            int index = (int)eventID;

            if (index > listenerTarget.Length)
            {
                UnityEngine.Debug.LogError("EventDefine Error : " + eventID);
            }

            for (int i = 0; i < listenerTarget[index].Count; i++)
            {
                TDelegate <TParam> tempDelegate = listenerTarget[index][i] as TDelegate <TParam>;

                if (tempDelegate != null)
                {
                    tempDelegate(param);
                }
            }
        }
コード例 #23
0
        /// <summary>
        ///		Removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate.
        /// </summary>
        /// <typeparam name="TDelegate">The type of the delegate.</typeparam>
        /// <param name="source">The delegate from which to remove the invocation list of <paramref name="value"/>.</param>
        /// <param name="value">The delegate that supplies the invocation list to remove from the invocation list of <paramref name="source"/>.</param>
        /// <returns>A new delegate with an invocation list formed by taking the invocation list of <paramref name="source"/> and removing the last occurrence of the invocation list of <paramref name="value"/>, if the invocation list of <paramref name="value"/> is found within the invocation list of <paramref name="source"/>. Returns <paramref name="source"/> if <paramref name="value"/> is <see langword="null"/> or if the invocation list of <paramref name="value"/> is not found within the invocation list of <paramref name="source"/>. Returns <see langword="null"/> if the invocation list of <paramref name="value"/> is equal to the invocation list of <paramref name="source"/> or if <paramref name="source"/> is <see langword="null"/>.</returns>
        /// <seealso cref="Delegate.Remove(Delegate, Delegate)"/>
        public static TDelegate Remove <[DelegateConstraint] TDelegate>(TDelegate source, TDelegate value) where TDelegate : class
        {
            if (ReferenceEquals(source, null))
            {
                return(null);
            }
            Delegate             sourceDelegate = source as Delegate;
            Delegate             valueDelegate  = value as Delegate;
            WeakDelegateSuragate sourceSuragate;

            if (GetCombinedHolder(sourceDelegate.Method, out sourceSuragate))
            {
                Delegate             newDelegate = CreateDynamicDelegate(source, null, sourceDelegate, null);
                WeakDelegateSuragate valueSuragate;
                suragates.Add(newDelegate.Method, new WeakReference <WeakDelegateSuragate>(GetCombinedHolder(valueDelegate.Method, out valueSuragate) ? sourceSuragate.Remove(valueSuragate) : sourceSuragate.Remove(valueDelegate)));
                return(newDelegate as TDelegate);
            }
            return(Delegate.Remove(sourceDelegate, valueDelegate) as TDelegate);
        }
コード例 #24
0
            public WeakEventHandler(EventInfo info, object owner, TDelegate handler)
            {
                var @delegate = handler as Delegate;

                if (@delegate.Target == null)
                {
                    throw new ArgumentException("WeakEvent subscription only makes sense with instance methods");
                }

                m_target = new WeakReference(@delegate.Target);

                var parameters = @delegate.Method
                                 .GetParameters()
                                 .Select(parameter => Expression.Parameter(parameter.ParameterType))
                                 .ToArray();

                var targetDeclaration = Expression.Variable(typeof(object));                                                                                                            //object target;
                var targetAssignement = Expression.Assign(targetDeclaration, Expression.Invoke((Expression <Func <object> >)(() => m_target.Target), Enumerable.Empty <Expression>())); // target = m_target.Target;
                var ifCondition       = Expression.NotEqual(targetDeclaration, Expression.Constant(null, typeof(object)));                                                              // target != null
                var cast           = Expression.Convert(targetDeclaration, m_target.Target.GetType());                                                                                  // (T) target
                var callDelegate   = Expression.Call(cast, @delegate.Method, parameters.Cast <Expression>());                                                                           //m_method.Invoke(target,params);
                var weakDelAcccess = Expression.Convert(Expression.Invoke((Expression <Func <Delegate> >)(() => WeakDelegate as Delegate), Enumerable.Empty <Expression>()), typeof(TDelegate));
                var removeHandler  = owner == null                                                                                                                                      // owner.event -= WeakDelegate
                    ? Expression.Call(info.RemoveMethod, weakDelAcccess)
                    : Expression.Call(Expression.Constant(owner, info.DeclaringType), info.RemoveMethod, weakDelAcccess);

                var ifthenElseInvoke = Expression.IfThenElse(ifCondition, callDelegate, removeHandler); //if

                WeakDelegate = Expression.Lambda <TDelegate>(Expression.Block(targetDeclaration.IntoANewArray(), targetAssignement, ifthenElseInvoke), parameters).Compile();

                /*void Invoke(params)
                 * {
                 *  object target = m_target.Target;
                 *  if (target != null)
                 *      ((T)target).Invoke(params)
                 *  else
                 *      owner.event -= WeakDelegate
                 * }*/
            }
コード例 #25
0
 public static Expression <TDelegate> ToExpression <[DelegateConstraint] TDelegate>(this TDelegate @delegate)
     where TDelegate : class => throw new NotImplementedException();
コード例 #26
0
 public TController After(TDelegate taskDelegate) => After(GlyphScheduler.GetDelegateTask(taskDelegate));
コード例 #27
0
 public TController Before(TDelegate taskDelegate) => Before(GlyphScheduler.GetDelegateTask(taskDelegate));
コード例 #28
0
 public Disposer(EventWrapper <TDelegate, TEventArgs> observable, TDelegate handler)
 {
     _observable = observable;
     _handler    = handler;
 }
コード例 #29
0
ファイル: MatchBuilder.cs プロジェクト: natilivni/dotNext
 private protected abstract MatchBuilder Build(MatchBuilder builder, TDelegate scope);
コード例 #30
0
ファイル: MatchBuilder.cs プロジェクト: natilivni/dotNext
 public MatchBuilder Build(TDelegate scope) => Build(builder, scope);