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


C# System.Action类代码示例

本文整理汇总了C#中System.Action的典型用法代码示例。如果您正苦于以下问题:C# Action类的具体用法?C# Action怎么用?C# Action使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Action类属于System命名空间,在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SortingTest

        public void SortingTest()
        {
            Action<int[]>[] actions = new Action<int[]>[]
            {
                BubbleSort.Sort,
                data => BucketSort.Sort(data, SortingTests.MaxValue),
                data => CountingSort.Sort(data, SortingTests.MaxValue),
                HeapSort.Sort,
                InsertionSort.Sort,
                MergeSort.Sort,
                QuickSort.Sort,
                data => RadixSort.Sort(data, SortingTests.MaxValue),
            };

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int[] data = ArrayUtilities.CreateRandomArray(j, 0, SortingTests.MaxValue);
                    int[][] results = new int[actions.Length][];

                    for (int k = 0; k < actions.Length; k++)
                    {
                        results[k] = new int[data.Length];
                        Array.Copy(data, results[k], data.Length);

                        actions[k](results[k]);
                        Assert.IsTrue(ArrayUtilities.AreEqual(results[k], results[0]));
                    }
                }
            }
        }
开发者ID:mmoroney,项目名称:Algorithms,代码行数:32,代码来源:SortingTests.cs

示例2: SortedMergeTest

        public void SortedMergeTest()
        {
            Action<int[], int[]>[] actions = new Action<int[], int[]>[]
            {
                SortedMerge.BruteForce,
                SortedMerge.SinglePass
            };

            for(int i = 0; i < 10; i++)
            {
                int[] A = ArrayUtilities.CreateRandomArray(40, 0, 20);
                int[] B = ArrayUtilities.CreateRandomArray(20, 0, 20);

                Array.Sort(A, 0, A.Length / 2);
                Array.Sort(B);

                int[][] results = new int[actions.Length][];

                for(int j = 0; j < actions.Length; j++)
                {
                    results[j] = new int[A.Length];
                    Array.Copy(A, results[j], A.Length);
                    int[] copyB = new int[B.Length];
                    Array.Copy(B, copyB, B.Length);

                    actions[j](results[j], copyB);
                    Assert.IsTrue(ArrayUtilities.AreEqual(results[0], results[j]));
                }
            }
        }
开发者ID:mmoroney,项目名称:Algorithms,代码行数:30,代码来源:SortedMerge.cs

示例3: MenuForm

        /// <summary>
        /// Creates a new menu form.
        /// </summary>
        /// <param name="title">Window title.</param>
        /// <param name="itemNames">Item names.</param>
        /// <param name="actions">Actions.</param>
        public MenuForm(string title, string[] itemNames, Action[] actions)
        {
            Title = title;
            SelectedIndex = -1;

            if (itemNames == null || actions == null)
                return;
            if (itemNames.Length != actions.Length)
                return;

            var stackLayout = new StackLayout {Orientation = Orientation.Vertical, HorizontalContentAlignment = HorizontalAlignment.Stretch };

            for (int i = 0; i < itemNames.Length; i++)
            {
                var idx = i;

                var button = new Button { Text = itemNames[idx], Size = new Size(240, 60) }; 
                button.Click += (s, e) =>
                {
                    actions[idx]();
                    SelectedIndex = idx;
                    this.Close();
                };

                stackLayout.Items.Add(new StackLayoutItem(button, true));
            }

            Content = stackLayout;
            Size = new Size(-1, -1);
        }
开发者ID:gitter-badger,项目名称:dot-imaging,代码行数:36,代码来源:MenuForm.cs

示例4: IncrementIntegerTest

        public void IncrementIntegerTest()
        {
            Action<List<int>>[] actions = new Action<List<int>>[]
            {
                IncrementInteger.Convert,
                IncrementInteger.SinglePass
            };

            int digits = 0;
            for (int i = 0; i <= 1000; i++)
            {
                if (i % 10 == 0)
                    digits++;

                for(int j = 0; j < actions.Length; j++)
                {
                    List<int> list = new List<int>();
                    for (int k = 0; k < digits; k++)
                        list.Insert(0, 0);

                    IncrementInteger.ToList(i, list);
                    actions[j](list);
                    Assert.AreEqual(IncrementInteger.ToInt(list), i + 1);
                }
            }
        }
开发者ID:mmoroney,项目名称:Algorithms,代码行数:26,代码来源:IncrementInteger.cs

示例5: VerifyPath

        /// <summary>
        /// Enumerates the segments in a path and calls a corresponding delegate verifier on each segment.
        /// Do not overuse this method: most test cases don't need to over-baseline what the expected segments are.
        /// </summary>
        public static void VerifyPath(ODataPath path, Action<ODataPathSegment>[] segmentVerifiers)
        {
            path.Count().Should().Be(segmentVerifiers.Count());

            var i = 0;
            foreach (var segment in path)
            {
                segmentVerifiers[i++](segment);
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:14,代码来源:VerificationHelpers.cs

示例6: ProcessMovieImport

		public static void ProcessMovieImport(string fn, Action<string> conversionErrorCallback, Action<string> messageCallback)
		{
			var d = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
			string errorMsg;
			string warningMsg;
			var m = ImportFile(fn, out errorMsg, out warningMsg);

			if (!string.IsNullOrWhiteSpace(errorMsg))
			{
				conversionErrorCallback(errorMsg);
			}

			if (!string.IsNullOrWhiteSpace(warningMsg))
			{
				messageCallback(warningMsg);

			}
			else
			{
				messageCallback(Path.GetFileName(fn) + " imported as " + m.Filename);
			}

			if (!Directory.Exists(d))
			{
				Directory.CreateDirectory(d);
			}
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:27,代码来源:MovieImport.cs

示例7: ConfigureForIIS

        /// <summary>
        /// Sets the delegate to use when configuring the application's <see cref="GlobalConfiguration.Configuration"/>.
        /// </summary>
        /// <param name="configurationDelegate">The configuration delegate.</param>
        /// <returns>Current <see cref="WebApiManagerBuilder"/> instance.</returns>
        /// <remarks></remarks>
        public ApplicationConfigurationBuilder ConfigureForIIS(Action<HttpConfiguration> configurationDelegate)
        {
            _AspNetHttpConfigurationDelegate = configurationDelegate;
            Setup();

            return Builder;
        }
开发者ID:chihoyeung,项目名称:NContext,代码行数:13,代码来源:WebApiManagerBuilder.cs

示例8: Invoke

        public static void Invoke(this Control uiElement, Action updater, bool forceSynchronous = true)
        {
            if (uiElement == null)
            {
                throw new ArgumentNullException("uiElement");
            }

            if (uiElement.InvokeRequired)
            {
                if (forceSynchronous)
                {
                    try
                    {
                        uiElement.Invoke((Action)delegate { Invoke(uiElement, updater, forceSynchronous); });
                    }
                    catch (Exception e) { }
                }
                else
                {
                    uiElement.BeginInvoke((Action)delegate { Invoke(uiElement, updater, forceSynchronous); });
                }
            }
            else
            {
                if (!uiElement.IsDisposed)
                {
                    updater();
                }
            }
        }
开发者ID:CheeseSoftware,项目名称:MasterBot,代码行数:30,代码来源:SafeInvoke.cs

示例9: UpdateHandler

        public UpdateHandler(DataTrade trade, DataFeed feed, Action<SymbolInfo[], AccountInfo, Quote> updateCallback, Processor processor)
        {
            if (trade == null)
                throw new ArgumentNullException(nameof(trade));

            if (feed == null)
                throw new ArgumentNullException(nameof(feed));

            if (updateCallback == null)
                throw new ArgumentNullException(nameof(updateCallback));

            if (processor == null)
                throw new ArgumentNullException(nameof(processor));

            this.updateCallback = updateCallback;
            this.processor = processor;

            this.SyncRoot = new object();

            feed.SymbolInfo += this.OnSymbolInfo;
            feed.Tick += this.OnTick;

            trade.AccountInfo += this.OnAccountInfo;
            trade.BalanceOperation += this.OnBalanceOperation;
            trade.ExecutionReport += this.OnExecutionReport;
            trade.PositionReport += this.OnPositionReport;
        }
开发者ID:ifzz,项目名称:FDK,代码行数:27,代码来源:UpdateHandler.cs

示例10: WebMethod2

        //public async Task<string> WebMethod2()
        public void WebMethod2(Action<string> yield)
        {
            // ThreadLocal SynchronizationContext aware ConnectionPool?
            var n = new PerformanceResourceTimingData2ApplicationPerformance();

            var rid = n.Insert(
                new PerformanceResourceTimingData2ApplicationPerformanceRow
            {
                connectStart = 5,
                connectEnd = 13,

                // conversion done in AddParameter
                // .stack rewriter needs to store struct. can we create new byref struct parameters?
                //EventTime = DateTime.Now.AddDays(-0),

                // conversion done in Insert?
                z = new XElement("goo", "foo")
            }
            );

            // { LastInsertRowId = 2 }
            Console.WriteLine("after insert " + new { rid });


            var c = new PerformanceResourceTimingData2ApplicationPerformance().Count();

            Console.WriteLine(new { c, rid });

            // I/System.Console( 7320): {{ c = 18, rid = 18 }}
            //return new { c, rid }.ToString();
            yield(
                "TestAndroidInsert " + new { c, rid }.ToString()
                );

        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:36,代码来源:ApplicationWebService.cs

示例11: CreateTchatCommand

 public static void CreateTchatCommand(string name, string help, Action<string[], Bot> action)
 {
     string commandName = name.ToLowerInvariant();
     if (m_commands.Count(entry => entry.CommandName == commandName) == 1)
         throw new InvalidOperationException(String.Format("Command {0} already exists.", name));
     m_commands.Add(new TchatCommand(name, help, action));
 }
开发者ID:a3gis,项目名称:BehaviorIsManaged,代码行数:7,代码来源:GameCommands.cs

示例12: CreateSavedSearch

        /// <summary>
        /// Adds a saved search to your twitter account
        /// </summary>
        /// <param name="query">Search query to add</param>
        /// <param name="callback">Async Callback used in Silverlight queries</param>
        /// <returns>SavedSearch object</returns>
        public static SavedSearch CreateSavedSearch(this TwitterContext ctx, string query, Action<TwitterAsyncResponse<SavedSearch>> callback)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentException("query is required.", "query");
            }

            var savedSearchUrl = ctx.BaseUrl + "saved_searches/create.json";

            var reqProc = new SavedSearchRequestProcessor<SavedSearch>();

            ITwitterExecute exec = ctx.TwitterExecutor;
            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostToTwitter(
                    savedSearchUrl,
                    new Dictionary<string, string>
                    {
                        { "query", query }
                    },
                    response => reqProc.ProcessActionResult(response, SavedSearchAction.Create));

            SavedSearch result = reqProc.ProcessActionResult(resultsJson, SavedSearchAction.Create);
            return result;
        }
开发者ID:prog-moh,项目名称:LinqToTwitter,代码行数:31,代码来源:SavedSearchExtensions.cs

示例13: AnalyzeSymbol

        public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
        {
            if (symbol.TypeKind != TypeKind.Enum)
            {
                return;
            }

            var flagsAttribute = WellKnownTypes.FlagsAttribute(compilation);
            if (flagsAttribute == null)
            {
                return;
            }

            var zeroValuedFields = GetZeroValuedFields(symbol).ToImmutableArray();

            bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass == flagsAttribute);
            if (hasFlagsAttribute)
            {
                CheckFlags(symbol, zeroValuedFields, addDiagnostic);
            }
            else
            {
                CheckNonFlags(symbol, zeroValuedFields, addDiagnostic);
            }
        }
开发者ID:pheede,项目名称:roslyn,代码行数:25,代码来源:CA1008DiagnosticAnalyzer.cs

示例14: VnrSplitter

 public static SplitterBuilder VnrSplitter(this HtmlHelper helper, SplitterBuilderInfo builderInfo)
 {
     var pane = new Action<SplitterPaneFactory>(p =>
     {
         foreach (var item in builderInfo.Panes)
         {
             if (!string.IsNullOrWhiteSpace(item.Value.Content))
             {
                 p.Add()
                     .Content(item.Value.Content)
                     .Collapsible(item.Value.Collapsible)
                     .Scrollable(item.Value.Scrollable)
                     .Size(item.Value.Size)
                     .Resizable(item.Value.Resizable);
             }
             else if (!string.IsNullOrEmpty(item.Value.Controller) || !string.IsNullOrEmpty(item.Value.ActionName))
             {
                 p.Add()
                     .LoadContentFrom(item.Value.ActionName, item.Value.Controller)
                     .Collapsible(item.Value.Collapsible)
                     .Scrollable(item.Value.Scrollable)
                     .Size(item.Value.Size)
                     .Resizable(item.Value.Resizable);
             }
         }
     });
     var splitterBuilder = helper.Kendo().Splitter()
         .Orientation(builderInfo.Orientation)
         .Name(builderInfo.Name)
         .HtmlAttributes(new {style="height:"+builderInfo.Height+"px;"})
         .Panes(pane);
     return splitterBuilder;
 }
开发者ID:dtafe,项目名称:vnr,代码行数:33,代码来源:VnrSplitterBuilder.cs

示例15: PostAsync

 public EventSignal<IResponse> PostAsync(string url, Action<IRequest> prepareRequest, Dictionary<string, string> postData)
 {
     var returnSignal = new EventSignal<IResponse>();
     var signal = HttpHelper.PostAsync(url, request => prepareRequest(new HttpWebRequestWrapper(request)), postData);
     signal.Finished += (sender, e) => returnSignal.OnFinish(new HttpWebResponseWrapper(e.Result.Result) { Exception = e.Result.Exception, IsFaulted = e.Result.IsFaulted });
     return returnSignal;
 }
开发者ID:robink-teleopti,项目名称:SignalR,代码行数:7,代码来源:DefaultHttpClient.cs


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