[corlib] Avoid unnecessary ephemeron array resizes
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Resources / ResourceUtilities.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Resources 
5 {
6     using System;
7     using System.Windows;
8     using System.Activities.Presentation;
9
10     // <summary>
11     // Helper utilities for accessing values in ResourceDictionaries of controls
12     // </summary>
13     internal static class ResourceUtilities 
14     {
15
16         private const string TypeIconWidthKey = "TypeIconWidth";
17         private const string TypeIconHeightKey = "TypeIconHeight";
18
19         // <summary>
20         // Looks up a double based on the specified key, returning specified fallback value if not found
21         // </summary>
22         // <param name="element">Element to use as the starting point</param>
23         // <param name="key">Key to look up</param>
24         // <param name="fallbackValue">Fallback value to return if key is not found</param>
25         // <returns>Double from the resource or fallback value if not found</returns>
26         public static double GetDouble(FrameworkElement element, string key, double fallbackValue) 
27         {
28             if (element == null) 
29             {
30                 throw FxTrace.Exception.ArgumentNull("element");
31             }
32             if (string.IsNullOrEmpty(key)) 
33             {
34                 throw FxTrace.Exception.ArgumentNull("key");
35             }
36             return (double)(element.FindResource(key) ?? fallbackValue);
37         }
38
39         public static Size GetDesiredTypeIconSize(FrameworkElement queryRoot) 
40         {
41             return new Size(ResourceUtilities.GetDouble(queryRoot, TypeIconWidthKey, 16),
42                 ResourceUtilities.GetDouble(queryRoot, TypeIconHeightKey, 16));
43         }
44     }
45 }