当前位置: 首页>>代码示例>>C#>>正文


C# Func.Concat方法代码示例

本文整理汇总了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();
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:35,代码来源:RandomPayloadBuilder.cs

示例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;
            }
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:70,代码来源:TaskAsyncHelperFacts.cs


注:本文中的Func.Concat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。