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


C# Paragraph.Append方法代码示例

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


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

示例1: CompareINIs

        private void CompareINIs(INI file1, INI file2)
        {
            if (file1 == null || file2 == null)
                return;

            var paragraph1 = new Paragraph();
            var paragraph2 = new Paragraph();

            var matchedSections = new List<string>();
            var missedSectionsAccountedFor = new List<string>();

            foreach (var section in file1)
            {
                if (file2.ContainsKey(section.Key))
                {
                    //this section is in both INIs compare it and output
                    matchedSections.Add(section.Key);

                    //but first, lets take a moment to find any sections from file2 that may have been skipped at this point. Specifically sections that are not in file1 at all so we can write them out.
                    var file2SectionKeys = file2.Keys.ToList();
                    var file2SectionKeysNotSeenYet = file2SectionKeys.GetRange(0, file2SectionKeys.IndexOf(section.Key))
                                                    .Where(sectionKey => !matchedSections.Contains(sectionKey) //haven't matched it before
                                                    && !missedSectionsAccountedFor.Contains(sectionKey)        //haven't fixed it before
                                                    && !file1.ContainsKey(sectionKey));                        //won't be getting to it later

                    foreach (var missingSectionKey in file2SectionKeysNotSeenYet)
                    {
                        //this section is not in the first INI, display it as added

                        if (missingSectionKey.Length > 0)
                        {
                            paragraph1.AppendLine();
                            paragraph2.AppendLine(string.Format("[{0}]", missingSectionKey), Brushes.LightGreen, bold: true);
                        }
                        foreach (var keyvalue in file2[missingSectionKey])
                        {
                            //none of the lines can match
                            paragraph1.AppendLine();
                            paragraph2.AppendLine(string.Format("{0} = {1}", keyvalue.Key, keyvalue.Value), Brushes.LightGreen);
                        }
                        paragraph1.AppendLine();
                        paragraph2.AppendLine();

                        missedSectionsAccountedFor.Add(missingSectionKey);
                    }


                    //okay, now we continue with this section
                    var matchedKeys = new List<string>();
                    var missedKeysAccountedFor = new List<string>();

                    if (section.Key.Length > 0)
                    {
                        paragraph1.AppendLine(string.Format("[{0}]", section.Key), bold: true);
                        paragraph2.AppendLine(string.Format("[{0}]", section.Key), bold: true);
                    }
                    foreach (var keyvalue in section.Value)
                    {
                        //now check each line
                        if (file2[section.Key].ContainsKey(keyvalue.Key))
                        {
                            //this key is in both sections
                            matchedKeys.Add(keyvalue.Key);

                            //lets take a moment to find any keys from section2 that may have been skipped at this point. Specifically, keys are not in section1 at all, so we can write them out.
                            var section2Keys = file2[section.Key].Keys.ToList();
                            var section2KeysNotSeenYet = section2Keys.GetRange(0, section2Keys.IndexOf(keyvalue.Key))
                                                        .Where(key => !matchedKeys.Contains(key) //haven't matched it before
                                                        && !missedKeysAccountedFor.Contains(key) //haven't taken care of it before
                                                        && !section.Value.ContainsKey(key));     //won't be getting to it

                            foreach (var missingKey in section2KeysNotSeenYet)
                            {
                                paragraph1.AppendLine();
                                paragraph2.AppendLine(string.Format("{0} = {1}", missingKey, file2[section.Key][missingKey]), Brushes.LightGreen);
                                missedKeysAccountedFor.Add(missingKey);
                            }

                            //okay, now we continue with this new match

                            //commented out, would only color the part of the INI line that changed, now its set to do the whole line
                            //paragraph1.Append(string.Format("{0} = ", keyvalue.Key));
                            //paragraph2.Append(string.Format("{0} = ", keyvalue.Key));

                            if (keyvalue.Value == file2[section.Key][keyvalue.Key])
                            {
                                //values are the same
                                //paragraph1.AppendLine(string.Format("{0}", keyvalue.Value));
                                //paragraph2.AppendLine(string.Format("{0}", keyvalue.Value));
                                paragraph1.AppendLine(string.Format("{0} = {1}", keyvalue.Key, keyvalue.Value));
                                paragraph2.AppendLine(string.Format("{0} = {1}", keyvalue.Key, keyvalue.Value));
                            }
                            else
                            {
                                //values are different
                                //paragraph1.AppendLine(string.Format("{0}", keyvalue.Value), Brushes.LightGray);
                                //paragraph2.AppendLine(string.Format("{0}", file2[section.Key][keyvalue.Key]), Brushes.LightGray);
                                paragraph1.Append(string.Format("{0} = ", keyvalue.Key), Brushes.LightGray);
                                paragraph2.Append(string.Format("{0} = ", keyvalue.Key), Brushes.LightGray);
                                paragraph1.AppendLine(string.Format("{0}", keyvalue.Value), Brushes.Gray, Brushes.White);
//.........这里部分代码省略.........
开发者ID:BenVlodgi,项目名称:INICompare,代码行数:101,代码来源:MainWindow.xaml.cs


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