This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathResourceDictionaryUtilities.cs
55 lines (47 loc) · 1.73 KB
/
ResourceDictionaryUtilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.IO;
using System.IO.Packaging;
using System.Windows;
namespace GitHub.UI.Helpers.UnitTests
{
class ResourceDictionaryUtilities
{
public static string PackUriScheme { get; private set; }
public static Uri ToPackUri(string url)
{
// Calling `Application.Current` will install pack URI scheme via Application.cctor.
// This is needed when unit testing for the pack:// URL format to be understood.
if (Application.Current != null) { }
return new Uri(url);
}
public static string DumpMergedDictionaries(ResourceDictionary target, string url)
{
SetProperty(target, "Source", ToPackUri(url));
return DumpResourceDictionary(target);
}
static void SetProperty(object target, string name, object value)
{
var prop = target.GetType().GetProperty(name);
prop.SetValue(target, value);
}
public static string DumpResourceDictionary(ResourceDictionary rd, string indent = "")
{
var writer = new StringWriter();
DumpResourceDictionary(writer, rd);
return writer.ToString();
}
public static void DumpResourceDictionary(TextWriter writer, ResourceDictionary rd, string indent = "")
{
var source = rd.Source;
if (source != null)
{
writer.WriteLine(indent + source + " (" + rd.GetType().FullName + ") # " + rd.GetHashCode());
indent += " ";
}
foreach (var child in rd.MergedDictionaries)
{
DumpResourceDictionary(writer, child, indent);
}
}
}
}