-
Notifications
You must be signed in to change notification settings - Fork 1
net90_PropertyGridHelpers.Support_Support_GetResourcePath
dparvin edited this page Jan 11, 2026
·
12 revisions
Determines the resource path based on the specified property or related data type, filtered by the specified ResourceUsage.
public static string GetResourcePath(ITypeDescriptorContext context, Type type,
ResourceUsage resourceUsage = ResourceUsage.All, bool throwOnError = false)| parameter | description |
|---|---|
| context | The type descriptor context, which provides metadata about the property and its container. |
| type | The data type associated with the resource, typically an enum or a property type. |
| resourceUsage | The kind of resource to resolve (e.g., Strings, Images). This helps determine the most appropriate resource path when multiple paths are defined. |
| throwOnError | if set to true throw on error when the Dynamic Path Attribute is not setup correctly. |
A string containing the resource path based on the provided property or type. If no applicable attributes are found, the method returns the default resource path: "Properties.Resources".
| exception | condition |
|---|---|
| ArgumentNullException | Thrown if type is null. |
| ArgumentException | Thrown if resourceUsage is None. |
This method searches for the resource path using the following order of precedence:
- If the property has a
DynamicPathSourceAttributematching the given resourceUsage, it retrieves the path from the referenced property. - If the property or its type has a
ResourcePathAttributematching the specified resourceUsage, it uses the defined path. - If the type (or its underlying nullable type) is an enumeration and has a matching
ResourcePathAttribute, it uses the associated path. - If none of the above conditions are met, it defaults to
"Properties.Resources".
Example usage with static path:
[ResourcePath("Custom.Resources", resourceUsage: ResourceUsage.Strings)]
public enum MyEnum
{
Value1,
Value2
}
string path = GetResourcePath(null, typeof(MyEnum), ResourceUsage.Strings);
Console.WriteLine(path); // Outputs: "Custom.Resources"Example usage with dynamic path:
[DynamicPathSource(nameof(MyResourcePath), ResourceUsage.Images)]
public MyEnum ImageSelector { get; set; }
public string MyResourcePath => "Dynamic.Image.Resources";- enum ResourceUsage
- class Support
- namespace PropertyGridHelpers.Support
- assembly PropertyGridHelpers