本文整理匯總了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);
//.........這裏部分代碼省略.........