-
Notifications
You must be signed in to change notification settings - Fork 1
net90_PropertyGridHelpers.Attributes_DynamicPathSourceAttribute
dparvin edited this page Jan 11, 2026
·
14 revisions
Specifies that the resource path used to localize or visualize this property should be dynamically retrieved from another property on the same object.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class DynamicPathSourceAttribute : Attribute| parameter | description |
|---|---|
| pathPropertyName | The name of the property (on the same class) that returns a string resource path. |
| resourceUsage | The kind of resource this path will be used for. Defaults to All. |
| name | description |
|---|---|
| DynamicPathSourceAttribute(…) | Specifies that the resource path used to localize or visualize this property should be dynamically retrieved from another property on the same object. |
| static Get(…) | Resolves the most appropriate DynamicPathSourceAttribute for the given context and usage. |
| PathPropertyName { get; } | Gets the name of the property that contains the resource path to use for this context. The referenced property should return a string representing a fully qualified resource class name (e.g., "MyApp.Resources.MyStrings"). |
| ResourceUsage { get; } | Indicates what type of resource this path is intended for (e.g., Strings, Images). Used to filter when multiple attributes are present. |
This attribute is useful for making the resource path configurable at runtime or design time, especially when dealing with localized enum values, icons, or other resource-driven behaviors. You can apply multiple DynamicPathSourceAttribute instances to a single property, each with a different ResourceUsage value to target specific resource types (e.g. strings vs. images). Resolution logic will select the first matching path based on the requested resourceUsage.
Example 1: Dynamic string resource binding for enum display
[DynamicPathSource(nameof(MyResourcePath), ResourceUsage.Strings)]
public MyEnum DisplayOption { get; set; }
public string MyResourcePath => "MyApp.Strings.EnumResources";Example 2: Separate image path for visual enum dropdown
[DynamicPathSource(nameof(ImagePath), ResourceUsage.Images)]
public MyEnum IconChoice { get; set; }
public string ImagePath => "MyApp.Images.Icons";- namespace PropertyGridHelpers.Attributes
- assembly PropertyGridHelpers
- DynamicPathSourceAttribute.cs