Skip to content

net90_PropertyGridHelpers.Support_Support_GetResourcePath

dparvin edited this page Jan 11, 2026 · 12 revisions

Support.GetResourcePath method

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.

Return Value

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".

Exceptions

exception condition
ArgumentNullException Thrown if type is null.
ArgumentException Thrown if resourceUsage is None.

Remarks

This method searches for the resource path using the following order of precedence:

  1. If the property has a DynamicPathSourceAttribute matching the given resourceUsage, it retrieves the path from the referenced property.
  2. If the property or its type has a ResourcePathAttribute matching the specified resourceUsage, it uses the defined path.
  3. If the type (or its underlying nullable type) is an enumeration and has a matching ResourcePathAttribute, it uses the associated path.
  4. If none of the above conditions are met, it defaults to "Properties.Resources".

Examples

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";

See Also

Clone this wiki locally