本文整理汇总了C#中Action.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Action.Invoke方法的具体用法?C# Action.Invoke怎么用?C# Action.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Action
的用法示例。
在下文中一共展示了Action.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When
private void When(Action when)
{
using (_mocks.Playback())
{
when.Invoke();
}
}
示例2: Given
private void Given(Action given)
{
using (_mocks.Record())
{
given.Invoke();
}
}
示例3: WriteElementBlock
public static void WriteElementBlock(this XmlWriter xmlWriter, string localName, string ns, Action<XmlWriter> action)
{
xmlWriter.WriteStartElement(localName, ns);
action.Invoke(xmlWriter);
xmlWriter.WriteEndElement();
xmlWriter.Flush();
}
示例4: Configure
/// <summary>
/// Performs configuration for <see cref="GlobalConfiguration.Configuration"/> and ensures that it is
/// initialized.
/// </summary>
/// <param name="configurationCallback">The callback that will perform the configuration.</param>
public static void Configure(Action<HttpConfiguration> configurationCallback)
{
if (configurationCallback == null)
{
throw new ArgumentNullException("configurationCallback");
}
configurationCallback.Invoke(Configuration);
Configuration.EnsureInitialized();
}
示例5: Then
private void Then(Action then)
{
_mocks.ReplayAll();
then.Invoke();
}
示例6: TestExceptionFilter
private static void TestExceptionFilter(ApiController controller, Exception expectedException,
Action<HttpConfiguration> configure)
{
// Arrange
Exception actualException = null;
IHttpRouteData routeData = new HttpRouteData(new HttpRoute());
using (HttpRequestMessage request = new HttpRequestMessage())
using (HttpConfiguration configuration = new HttpConfiguration())
using (HttpResponseMessage response = new HttpResponseMessage())
{
HttpControllerContext context = new HttpControllerContext(configuration, routeData, request);
HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(configuration,
"Ignored", controller.GetType());
context.Controller = controller;
context.ControllerDescriptor = controllerDescriptor;
if (configure != null)
{
configure.Invoke(configuration);
}
Mock<IExceptionFilter> spy = new Mock<IExceptionFilter>();
spy.Setup(f => f.ExecuteExceptionFilterAsync(It.IsAny<HttpActionExecutedContext>(),
It.IsAny<CancellationToken>())).Returns<HttpActionExecutedContext, CancellationToken>(
(c, i) =>
{
actualException = c.Exception;
c.Response = response;
return Task.FromResult<object>(null);
});
configuration.Filters.Add(spy.Object);
// Act
HttpResponseMessage ignore = controller.ExecuteAsync(context, CancellationToken.None).Result;
}
// Assert
Assert.Same(expectedException, actualException);
}
示例7: CreateAuthenticationFilterChallenge
private static IAuthenticationFilter CreateAuthenticationFilterChallenge(
Action<HttpAuthenticationChallengeContext, CancellationToken> challenge)
{
Mock<IAuthenticationFilter> mock = new Mock<IAuthenticationFilter>();
mock.Setup(f => f.AuthenticateAsync(It.IsAny<HttpAuthenticationContext>(), It.IsAny<CancellationToken>()))
.Returns(() => Task.FromResult<object>(null));
mock.Setup(f => f.ChallengeAsync(It.IsAny<HttpAuthenticationChallengeContext>(),
It.IsAny<CancellationToken>()))
.Callback<HttpAuthenticationChallengeContext, CancellationToken>((c, t) =>
{
challenge.Invoke(c, t);
})
.Returns(() => Task.FromResult<object>(null));
return mock.Object;
}
示例8: CreatePrincipalService
private static IHostPrincipalService CreatePrincipalService(
Action<IPrincipal, HttpRequestMessage> setCurrentPrincipal)
{
Mock<IHostPrincipalService> mock = new Mock<IHostPrincipalService>();
mock.Setup(s => s.GetCurrentPrincipal(It.IsAny<HttpRequestMessage>())).Returns(CreateDummyPrincipal());
mock.Setup(s => s.SetCurrentPrincipal(It.IsAny<IPrincipal>(), It.IsAny<HttpRequestMessage>()))
.Callback<IPrincipal, HttpRequestMessage>((p, r) => { setCurrentPrincipal.Invoke(p, r); });
return mock.Object;
}
示例9: DelayAction
IEnumerator DelayAction(Action act, float delay)
{
yield return new WaitForSeconds(delay);
act.Invoke();
}
示例10: HandleException
public static void HandleException(bool exceptionDefaultOrBeforeAwait, bool exceptionAfterAwait, Action action)
{
bool hasException = false;
SetExceptionInjection(exceptionDefaultOrBeforeAwait, exceptionAfterAwait);
try
{
action.Invoke();
}
catch (Exception ex)
{
hasException = true;
Debug.WriteLine("Exception: {0}", ex.Message);
}
AssertTransactionNull();
Assert.Equal<bool>(hasException, true);
ResetExceptionInjection();
}
示例11: HandleSendAsyncCompletion
private async void HandleSendAsyncCompletion(Task task, TimeSpan timeout, Action<object> callback, object state)
{
try
{
await task;
}
catch (Exception)
{
_pendingWritingMessageException = WebSocketHelper.CreateExceptionOnTaskFailure(task, timeout,
WebSocketHelper.SendOperation);
}
finally
{
if (WcfEventSource.Instance.WebSocketAsyncWriteStopIsEnabled())
{
WcfEventSource.Instance.WebSocketAsyncWriteStop(WebSocket.GetHashCode());
}
callback.Invoke(state);
}
}
示例12: HandleCloseOutputAsyncCompletion
private async void HandleCloseOutputAsyncCompletion(Task task, TimeSpan timeout, Action<object> callback, object state)
{
try
{
await task;
}
catch (Exception)
{
_pendingWritingMessageException = WebSocketHelper.CreateExceptionOnTaskFailure(task, timeout, WebSocketHelper.CloseOperation);
}
finally
{
callback.Invoke(state);
}
}
示例13: WriteEndOfMessageAsync
public async void WriteEndOfMessageAsync(Action<object> callback, object state)
{
if (WcfEventSource.Instance.WebSocketAsyncWriteStartIsEnabled())
{
// TODO: Open bug about not emitting the hostname/port
WcfEventSource.Instance.WebSocketAsyncWriteStart(
_webSocket.GetHashCode(),
0,
string.Empty);
}
var timeoutHelper = new TimeoutHelper(_closeTimeout);
var cancelTokenTask = timeoutHelper.GetCancellationTokenAsync();
try
{
var cancelToken = await cancelTokenTask;
await _webSocket.SendAsync(new ArraySegment<byte>(Array.Empty<byte>(), 0, 0), _outgoingMessageType, true, cancelToken);
if (WcfEventSource.Instance.WebSocketAsyncWriteStopIsEnabled())
{
WcfEventSource.Instance.WebSocketAsyncWriteStop(_webSocket.GetHashCode());
}
}
catch (Exception ex)
{
if (Fx.IsFatal(ex))
{
throw;
}
if (cancelTokenTask.Result.IsCancellationRequested)
{
throw Fx.Exception.AsError(
new TimeoutException(InternalSR.TaskTimedOutError(timeoutHelper.OriginalTimeout)));
}
throw WebSocketHelper.ConvertAndTraceException(ex, timeoutHelper.OriginalTimeout,
WebSocketHelper.SendOperation);
}
finally
{
callback.Invoke(state);
}
}
示例14: OnDesignPanelFirstTimeActivated
private void OnDesignPanelFirstTimeActivated(Action<XRDesignPanel> handler)
{
DesignMdiController.DesignPanelLoaded += (sender1, designLoadedArgs) =>
{
var designPanel = (XRDesignPanel)sender1;
EventHandler activated = null;
activated = (sender2, emptyArgs) =>
{
// remove handler after the first time it is activated
designLoadedArgs.DesignerHost.Activated -= activated;
handler.Invoke(designPanel);
};
designLoadedArgs.DesignerHost.Activated += activated;
};
}
示例15: BeginInvoke
/// <summary>
/// Invoke in UI thread.
/// </summary>
public void BeginInvoke(Action a)
{
a.Invoke();
}