Exemple #1
0
        /// <summary>
        /// Attempts to update the context of the bound action stored in the field. Returns <c>false</c> if the field is <c>null</c>.
        /// </summary>
        /// <param name="contextUpdater">The function used to update an existing context. This may be called more than once if more than one thread attempts to simultanously update the context.</param>
        public bool TryUpdateContext(Func <T, T> contextUpdater)
        {
            while (true)
            {
                var original = Interlocked.CompareExchange(ref _field, _field, _field);
                if (original is null)
                {
                    return(false);
                }

                var updatedContext = new BoundAction(original, contextUpdater);
                var result         = Interlocked.CompareExchange(ref _field, updatedContext, original);
                if (ReferenceEquals(original, result))
                {
                    return(true);
                }
            }
        }
 /// <summary>
 /// Attempts to update the context of the bound action stored in the field. Returns <c>false</c> if the field is <c>null</c>.
 /// </summary>
 /// <param name="contextUpdater">The function used to update an existing context. This may be called more than once if more than one thread attempts to simultaneously update the context.</param>
 public bool TryUpdateContext(Func <T, T> contextUpdater)
 {
     _ = contextUpdater ?? throw new ArgumentNullException(nameof(contextUpdater));
     while (true)
     {
         var original = Interlocked.CompareExchange(ref _field, _field, _field);
         if (original == null)
         {
             return(false);
         }
         var updatedContext = new BoundAction(original, contextUpdater);
         var result         = Interlocked.CompareExchange(ref _field, updatedContext, original);
         if (ReferenceEquals(original, result))
         {
             return(true);
         }
     }
 }
Exemple #3
0
        public void BoundAction_Matches_WhenRouteAndParametersMatch_And_CaseIsDifferent()
        {
            var actionParameters = new RouteValueDictionary
            {
                { "param1", "test" },
                { "param2", "test2" }
            };

            var otherActionParameters = new RouteValueDictionary
            {
                { "param1", "TEST" },
                { "PARAM2", "test2" }
            };

            var boundAction      = new BoundAction("TESTCONTROLLER", "action", actionParameters);
            var otherBoundAction = new BoundAction("testController", "ACTION", otherActionParameters);

            Assert.That(boundAction.Matches(otherBoundAction), Is.True);
        }
Exemple #4
0
        public void BoundAction_Matches_WhenRouteAndParametersMatch()
        {
            var actionParameters = new RouteValueDictionary
            {
                { "param1", "test" },
                { "param2", "test2" }
            };

            var otherActionParameters = new RouteValueDictionary
            {
                { "param1", "test" },
                { "param2", "test2" }
            };

            var boundAction      = new BoundAction("testController", "action", actionParameters);
            var otherBoundAction = new BoundAction("testController", "action", otherActionParameters);

            Assert.That(boundAction.Matches(otherBoundAction), Is.True);
        }
 public BoundAction(BoundAction originalBoundAction, Func <T, T> contextUpdater)
 {
     _action  = originalBoundAction._action;
     _context = contextUpdater(originalBoundAction._context);
 }
Exemple #6
0
 public BoundAction(BoundAction originalBoundAction, Func <T, T> contextUpdater)
 {
     Action  = originalBoundAction.Action;
     Context = contextUpdater(originalBoundAction.Context);
 }
Exemple #7
0
 /// <summary>
 /// Initializes the field with the specified action and context.
 /// </summary>
 /// <param name="action">The action delegate.</param>
 /// <param name="context">The context.</param>
 public BoundActionField(Action <T> action, T context)
 {
     _field = new BoundAction(action, context);
 }
 /// <summary>
 /// Initializes the field with the specified action and context.
 /// </summary>
 /// <param name="action">The action delegate.</param>
 /// <param name="context">The context.</param>
 public BoundAsyncActionField(Func <T, ValueTask> action, T context)
 {
     field = new BoundAction(action, context);
 }