本文整理汇总了C#中Func.Concat方法的典型用法代码示例。如果您正苦于以下问题:C# Func.Concat方法的具体用法?C# Func.Concat怎么用?C# Func.Concat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func.Concat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRandomPayload
/// <summary>
/// Generates an arbitrary top load payload based on the maximum version supplied.
/// </summary>
/// <param name="random">Random generator for generating arbitrary payloads</param>
/// <param name="model">The model to add any new types to</param>
/// <param name="version">Maximum version for generated payloads.</param>
/// <returns>A top level payload.</returns>
public static ODataPayloadElement GetRandomPayload(IRandomNumberGenerator random, EdmModel model, ODataVersion version = ODataVersion.V4)
{
ExceptionUtilities.CheckArgumentNotNull(random, "random");
ExceptionUtilities.CheckArgumentNotNull(model, "model");
Func<ODataPayloadElement>[] payloadCalls = new Func<ODataPayloadElement>[]
{
() => { return GetComplexInstanceCollection(random, model, version); },
() => { return GetComplexProperty(random, model, version); },
() => { return GetDeferredLink(); },
() => { return GetLinkCollection(); },
() => { return GetEntityInstance(random, model, version); },
() => { return GetEntitySetInstance(random, model); },
() => { return GetODataErrorPayload(random); },
() => { return GetPrimitiveCollection(random); },
() => { return GetPrimitiveProperty(random, model); },
() => { return GetPrimitiveValue(random, model); },
};
payloadCalls.Concat(new Func<ODataPayloadElement>[]
{
() => { return GetComplexMultiValueProperty(random, model, version); },
() => { return GetPrimitiveMultiValueProperty(random); },
});
var payloadCall = random.ChooseFrom(payloadCalls);
return payloadCall();
}
示例2: TaskAsyncHelpersPreserveCulture
public void TaskAsyncHelpersPreserveCulture()
{
TaskCompletionSource<CultureInfo> tcs = null;
TaskCompletionSource<CultureInfo> uiTcs = null;
var defaultCulture = Thread.CurrentThread.CurrentCulture;
var defaultUiCulture = Thread.CurrentThread.CurrentUICulture;
var testCulture = new CultureInfo("zh-Hans");
var testUICulture = new CultureInfo("zh-CN");
Func<Task> saveThreadCulture = () =>
{
tcs.SetResult(Thread.CurrentThread.CurrentCulture);
uiTcs.SetResult(Thread.CurrentThread.CurrentUICulture);
return TaskAsyncHelper.Empty;
};
Action<IEnumerable<Func<Task<object>>>, Action<Task<object>>> ensureCulturePreserved = (taskGenerators, testAction) =>
{
foreach (var taskGenerator in taskGenerators)
{
tcs = new TaskCompletionSource<CultureInfo>();
uiTcs = new TaskCompletionSource<CultureInfo>();
testAction(taskGenerator());
Assert.Equal(testCulture, tcs.Task.Result);
Assert.Equal(testUICulture, uiTcs.Task.Result);
}
};
try
{
Thread.CurrentThread.CurrentCulture = testCulture;
Thread.CurrentThread.CurrentUICulture = testUICulture;
var successfulTaskGenerators = new Func<Task<object>>[]
{
() => TaskAsyncHelper.FromResult<object>(null), // Completed
() => TaskAsyncHelper.Delay(TimeSpan.FromMilliseconds(50)).Then(() => (object)null), // Async Completed
};
// Non-generic Then with sync/async completed tasks
ensureCulturePreserved(successfulTaskGenerators, task => task.Then(saveThreadCulture));
var faultedTcs = new TaskCompletionSource<object>();
var canceledTcs = new TaskCompletionSource<object>();
faultedTcs.SetException(new Exception());
canceledTcs.SetCanceled();
var allTaskGenerators = successfulTaskGenerators.Concat(new Func<Task<object>>[]
{
() => faultedTcs.Task, // Faulted
() => canceledTcs.Task, // Canceled
() => TaskAsyncHelper.Delay(TimeSpan.FromMilliseconds(50)).Then(() => faultedTcs.Task), // Async Faulted
() => TaskAsyncHelper.Delay(TimeSpan.FromMilliseconds(50)).Then(() => canceledTcs.Task), // Async Canceled
});
// Generic ContinueWithPreservedCulture with sync/async faulted, canceled and completed tasks
ensureCulturePreserved(allTaskGenerators, task => task.ContinueWithPreservedCulture(_ => saveThreadCulture()));
// Verify that threads in the ThreadPool keep the default culture
tcs = new TaskCompletionSource<CultureInfo>();
uiTcs = new TaskCompletionSource<CultureInfo>();
TaskAsyncHelper.Delay(TimeSpan.FromMilliseconds(100)).ContinueWith(_ => saveThreadCulture());
Assert.Equal(defaultCulture, tcs.Task.Result);
Assert.Equal(defaultUiCulture, uiTcs.Task.Result);
}
finally
{
Thread.CurrentThread.CurrentCulture = defaultCulture;
Thread.CurrentThread.CurrentUICulture = defaultUiCulture;
}
}