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


C# List.Aggregate方法代码示例

本文整理汇总了C#中System.Windows.Documents.List.Aggregate方法的典型用法代码示例。如果您正苦于以下问题:C# List.Aggregate方法的具体用法?C# List.Aggregate怎么用?C# List.Aggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.List的用法示例。


在下文中一共展示了List.Aggregate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Convert

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Any(obj => obj == DependencyProperty.UnsetValue))
                return DependencyProperty.UnsetValue;

            if ((string)parameter == "ganttLine")
            {
                var length = ((DateTime)values[0] - (DateTime)values[1]).TotalMinutes / 30;
                var interval = (double)values[2];
                return length * interval;
            }
            else
            {
                var vals = new List<double>();
                foreach (object val in values)
                    //box化されたintがdoubleへ直接キャストできないのでいったんunbox化した後にdoubleにする
                    vals.Add(val is int ? (double)(int)val : (double)val);
                switch ((string)parameter)
                {
                    case "sum":
                        return vals.Cast<double>().Sum();
                    case "product":
                        return vals.Aggregate((val, tmp) => val * tmp);
                    default:
                        throw new NotImplementedException();
                }
            }
        }
开发者ID:ssksho,项目名称:CloudDining,代码行数:28,代码来源:DramControl.cs

示例2: _mrec_ParseUpdated

        private void _mrec_ParseUpdated(MathRecognition source, Recognition chchanged, bool updateMath)
        {
            /* Evaluate math if necessary */
            if (updateMath)
                try
                {
                    Evaluator.UpdateMath(_mrec.Ranges.Select((Parser.Range r) => r.Parse));
                }
                catch { }

            /* reset geometry displayed: range displays, etc */
            underlay.Children.Clear();
            inqCanvas.Children.Clear();

            /* set up to draw background yellow thing for range displays */
            Brush fill3 = new SolidColorBrush(Color.FromArgb(50, 255, 255, 180));
            Brush fill2 = new SolidColorBrush(Color.FromArgb(75, 255, 255, 180));
            Brush fill1 = new SolidColorBrush(Color.FromArgb(100, 255, 255, 180));
            Brush sqr3 = new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
            Brush sqr2 = new SolidColorBrush(Color.FromArgb(75, 0, 255, 0));
            Brush sqr1 = new SolidColorBrush(Color.FromArgb(100, 0, 255, 0));
            foreach (Parser.Range rrr in _mrec.Ranges)
            {
                Rct rangebbox = bbox(rrr.Strokes);
                CurrentStrokesBoudningBox = rangebbox;

                Rct box = rangebbox.Inflate(8, 8);

                /* draw yellow box */
                DrawingVisual dv = new DrawingVisual();
                DrawingContext dc = dv.RenderOpen();
                dc.DrawRoundedRectangle(fill3, null, box, 4, 4);
                dc.DrawRoundedRectangle(fill2, null, box.Inflate(-4, -4), 4, 4);
                dc.DrawRoundedRectangle(fill1, null, box.Inflate(-8, -8), 4, 4);
                dc.Close();
                underlay.Children.Add(dv);

                if (rrr.Parse != null)
                {
                    /* draw interpretation of entry */
                    if (rrr.Parse.expr != null)
                    {
                        dv = new DrawingVisual();
                        dc = dv.RenderOpen();
                        // this is an example of normal drawing of an expr
                        Rct nombb = starPadSDK.MathExpr.ExprWPF.EWPF.DrawTop(rrr.Parse.expr, 22, dc, Colors.Blue, new Pt(box.Left, box.Bottom + 24), true);
                        dc.Close();
                        underlay.Children.Add(dv);
                    }

                    /* draw result of computation, if any */
                    if (rrr.Parse.finalSimp != null)
                    {
                        Rct nombb;
                        Expr result = rrr.Parse.matrixOperationResult == null ? rrr.Parse.finalSimp : rrr.Parse.matrixOperationResult;
                        // this is an example of drawing an expr by getting a geometry of it first, so can be used for special effects, etc.
                        Geometry g = starPadSDK.MathExpr.ExprWPF.EWPF.ComputeGeometry(result, 22, out nombb);
                        System.Windows.Shapes.Path p = new System.Windows.Shapes.Path();
                        p.Data = g;
                        p.Stroke = Brushes.Red;
                        p.Fill = Brushes.Transparent;
                        p.StrokeThickness = 1;
                        p.RenderTransform = new TranslateTransform(box.Right + 10, box.Center.Y);
                        inqCanvas.Children.Add(p);
                    }

                    /* colorize ink. Ideally we would have kept track of which ink strokes had changes and only update colorization in those ranges affected
                     * by the changes. */
                    if (rrr.Parse.root != null) _colorizer.Colorize(rrr.Parse.root, rrr.Strokes, _mrec);
                }
            }

            /* Update alternates menu if user wrote a char */
            if (chchanged != null)
            {
                showSidebarAlts(new[] { chchanged }, new StroqCollection(_mrec.Sim[chchanged.strokes]));
            }
#if false
            /* print out log of current 1st-level parse, for debugging */
            List<string> resstrs = new List<string>();
            foreach(Parser.Range r in _mrec.Ranges) {
                Parser.ParseResult p = r.Parse;
                if(p != null && p.root != null)
                    resstrs.Add(p.root.Print());
            }
            if(resstrs.Count > 0) Console.WriteLine(resstrs.Aggregate((string a, string b) => a + " // " + b));
            foreach(Parser.Range r in _mrec.Ranges) {
                Parser.ParseResult pr = r.Parse;
                if(pr != null && pr.expr != null) Console.WriteLine(Text.Convert(pr.expr));
            }
#endif
        }
开发者ID:buptkang,项目名称:LogicPad,代码行数:92,代码来源:UserControl1.xaml.cs

示例3: RunAllTests

        private void RunAllTests(object sender, RoutedEventArgs e)
        {
            


            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();
            dialog.Description = "Please select a folder.";
            dialog.UseDescriptionForTitle = true; // This applies to the Vista style dialog only, not the old dialog.
          
           

            if ((bool)dialog.ShowDialog(this))
            {
              
          
                var filename = dialog.SelectedPath; // will switch to .Url later
                                                   //				var newText = File.ReadAllText (filename);
                                                   //				CSharpFilename.StringValue = Path.GetFileName (filename);
                                                   //				CSharpTextEditor.Replace (new NSRange (0, CSharpTextEditor.Value.Length), newText);
                                                   //				ViewModel.SourceCode = newText;
                                                   //				ViewModel.RecompileSource ();

                Func<string, string> strip = i => Regex.Replace(i ?? "", "[\r\n \t]+", " ").Trim();

                ViewModel.CompilerErrors = "\r\r" + ("Running all tests in : " + filename) + "\r\r";
                int passCount = 0;
                //			if (ResetStatus != null)
                //				ResetStatus.Stop();
                List<string> failedTestNames = new List<string>();
                ThreadPool.QueueUserWorkItem((h) =>
                    {

                        var allTests = Directory.EnumerateFiles(filename).Where(u => Path.GetExtension(u) == ".cs");
                        var count = 0;
                        foreach (var file in allTests)
                        {

                            var shortName = Path.GetFileName(file);
                            Console.WriteLine("-------------------------Running Test: " + shortName + "-------------------------");
                            ViewModel.CompilerErrors += "-------------------------Running Test: " + shortName + "-------------------------";

                            var text = FileExtensions.ReadFile(file);

                            if (text == "-1")
                                break;

                            Dispatcher.Invoke(() =>
                            {
                                CurrentSourceFile = file;
                                  TextEditor.Text = text;
//                                ViewModel.Recompile(CurrentSourceFile);

//                                CSharpFilename.StringValue = Path.GetFileName(file);

//                                CSharpTextEditor.Value = Extensions.ReadFile(file);
                            });

                            CSharpOutput = "Z..)";
                            CppOutput = "A..)";
                            //							ViewModel.CompileAndRunCode(shortName,File.ReadAllText(file));
                            CompileCSharp(false);
                            CompileD();
                            count++;

                            if (count % 20 == 0)
                            {
                                GC.Collect();
                            }

                            if (strip(CSharpOutput) == strip(CppOutput))
                            {
                                passCount++;
                                Dispatcher.Invoke(() =>
                                {
                                   

                                    ViewModel.CompilerErrors += String.Format("-------------------------Test {0} Passed:-------------------------\n", shortName);
                                });
                            }
                            else
                            {
                                Dispatcher.Invoke(() =>
                                {
                               
                                    ViewModel.CompilerErrors += String.Format("Test {0} Failed:\n", shortName);
                                    failedTestNames.Add(Path.GetFileNameWithoutExtension(shortName));

                                });
                            }
                           
                        }

                        ViewModel.CompilerErrors += String.Format("Summary \nTotal:{0} \nPass Rate:{1} \nPassed: {2} \nFailed: {3} {4}\n", allTests.Count(), (passCount * 100) / ((float)allTests.Count()), passCount, allTests.Count() - passCount, (allTests.Count() - passCount == 0) ? "" : failedTestNames.Aggregate((k, j) => k + " , " + j));

                    });



            }
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:100,代码来源:MainWindow.xaml.cs

示例4: CheckRawReportFolder

        private string CheckRawReportFolder()
        {
            var checkResults = new List<string>();

            NameValueCollection rawFilesPattern = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("RawFilesPattern");

            var bdreportFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["BDReport"].ToString());

            if (bdreportFiles.Length == 0)
                checkResults.Add("Miss BD Report File");
            else if (bdreportFiles.Length > 1)
                checkResults.Add("Exist duplicated BD Report Files");
            else
                _bdReportFileName = bdreportFiles[0];

            var projectidcFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["ProjectIDCReport"].ToString());
            if (projectidcFiles.Length == 0)
                checkResults.Add("Miss IDC Report By Project File");
            else if (projectidcFiles.Length > 1)
                checkResults.Add("Exist duplicated IDC Report By Project Files");
            else
                _idcProjectReportFileName = projectidcFiles[0];

            var employeeidcFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["EmployeeIDCReport"].ToString());

            if (employeeidcFiles.Length == 0)
                checkResults.Add("Miss IDC Report By Employee File");
            else if (employeeidcFiles.Length > 1)
                checkResults.Add("Exist duplicated IDC Report By Employee Files");
            else
                _idcEmployeeReportFileName = employeeidcFiles[0];

            var projectcontributionMTDFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["ProjectContributionMTDReport"].ToString());

            if (projectcontributionMTDFiles.Length == 0)
                checkResults.Add("Miss Project contribution report MTD File");
            else if (projectcontributionMTDFiles.Length > 1)
                checkResults.Add("Exist duplicated Project contribution report MTD Files");
            else
                _projectContributionMTDReportFileName = projectcontributionMTDFiles[0];

            var projectcontributionYTDFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["ProjectContributionYTDReport"].ToString());

            if (projectcontributionYTDFiles.Length == 0)
                checkResults.Add("Miss Project contribution report YTD File");
            else if (projectcontributionYTDFiles.Length > 1)
                checkResults.Add("Exist duplicated contribution report YTD Files");
            else
                _projectContributionYTDReportFileName = projectcontributionYTDFiles[0];

            if (checkResults.Count == 0)
                return string.Empty;
            else if (checkResults.Count == 1)
                return checkResults[0];
            else
                return checkResults.Aggregate<string>((i, j) => i + "; " + j);
        }
开发者ID:galaxyyao,项目名称:FinaChan_v2,代码行数:57,代码来源:MainWindow.xaml.cs


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