MCPcopy Create free account
hub / github.com/GPUOpen-Tools/GPU-Reshape / ResourceLocator

Class ResourceLocator

Source/UIX/Studio/ResourceLocator.cs:35–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33namespace Studio
34{
35 public class ResourceLocator
36 {
37 /// <summary>
38 /// Get a default style resource
39 /// </summary>
40 /// <param name="name">key of the resource</param>
41 /// <param name="defaultValue">default value if not found</param>
42 /// <typeparam name="T">expected type</typeparam>
43 /// <returns>found value or default</returns>
44 public static T? GetResource<T>(string name, T? defaultValue = default)
45 {
46 object? value = null;
47
48 if (!App.DefaultStyle.TryGetResource(name, null, out value) || value == null)
49 {
50#if DEBUG
51 Debug.WriteLine($"ResourceLocator - Failed to find resource '{name}'");
52#endif // DEBUG
53 return defaultValue;
54 }
55
56#if DEBUG
57 if (value is not T)
58 {
59 Debug.WriteLine($"ResourceLocator - Failed to convert resource '{name}' from {value.GetType()} to {typeof(T)}");
60 }
61#endif // DEBUG
62
63 return value is T ? (T)value : defaultValue;
64 }
65
66 /// <summary>
67 /// Get a brush resource
68 /// </summary>
69 /// <param name="name">key of the brush resource</param>
70 /// <param name="defaultValue">default value if not found</param>
71 /// <returns>found value or default</returns>
72 public static IBrush? GetBrush(string name, IBrush? defaultValue = default)
73 {
74 return GetResource<IBrush>(name, defaultValue);
75 }
76
77 /// <summary>
78 /// Get an icon from key
79 /// </summary>
80 /// <param name="name">icon key</param>
81 /// <returns>null if not found</returns>
82 public static StreamGeometry? GetIcon(string name)
83 {
84 // May not exist
85 if (!Application.Current!.Styles.TryGetResource(name, null, out object? resource))
86 {
87#if DEBUG
88 Debug.WriteLine($"ResourceLocator - Failed to find icon '{name}'");
89#endif // DEBUG
90 return null;
91 }
92

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected