| | | 1 | | using PropertyGridHelpers.PropertyDescriptors; |
| | | 2 | | using System; |
| | | 3 | | using System.ComponentModel; |
| | | 4 | | |
| | | 5 | | namespace PropertyGridHelpers.TypeDescriptors |
| | | 6 | | { |
| | | 7 | | #if NET8_0_OR_GREATER |
| | | 8 | | /// <summary> |
| | | 9 | | /// A type descriptor that provides localization for property names, categories, and descriptions. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="parent"> |
| | | 12 | | /// The parent <see cref="ICustomTypeDescriptor"/> to wrap. |
| | | 13 | | /// </param> |
| | | 14 | | /// <seealso cref="CustomTypeDescriptor"/> |
| | 16 | 15 | | public class LocalizedTypeDescriptor(ICustomTypeDescriptor parent) : CustomTypeDescriptor(parent) |
| | | 16 | | { |
| | | 17 | | #else |
| | | 18 | | /// <summary> |
| | | 19 | | /// A type descriptor that provides localization for property names, categories, and descriptions. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <seealso cref="CustomTypeDescriptor"/> |
| | | 22 | | public class LocalizedTypeDescriptor : CustomTypeDescriptor |
| | | 23 | | { |
| | | 24 | | /// <summary> |
| | | 25 | | /// Initializes a new instance of the <see cref="LocalizedTypeDescriptor"/> class. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <param name="parent"> |
| | | 28 | | /// The parent <see cref="ICustomTypeDescriptor"/> to wrap. |
| | | 29 | | /// </param> |
| | | 30 | | public LocalizedTypeDescriptor(ICustomTypeDescriptor parent) |
| | 16 | 31 | | : base(parent) { } |
| | | 32 | | #endif |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Returns the collection of properties for the current object, using the default attributes. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <returns> |
| | | 38 | | /// A <see cref="PropertyDescriptorCollection"/> containing the localized properties. |
| | | 39 | | /// </returns> |
| | 20 | 40 | | public override PropertyDescriptorCollection GetProperties() => GetProperties(null); |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Returns the collection of properties for the current object that match the specified attributes, |
| | | 44 | | /// with each property descriptor decorated to support localization. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="attributes"> |
| | | 47 | | /// An array of attributes to use as a filter. Only properties marked with one or more of these |
| | | 48 | | /// attributes will be included in the result. |
| | | 49 | | /// </param> |
| | | 50 | | /// <returns> |
| | | 51 | | /// A <see cref="PropertyDescriptorCollection"/> containing the filtered and localized properties. |
| | | 52 | | /// </returns> |
| | | 53 | | public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) |
| | 16 | 54 | | { |
| | 24 | 55 | | var baseProps = base.GetProperties(attributes); |
| | 24 | 56 | | var newProps = new PropertyDescriptor[baseProps.Count]; |
| | 64 | 57 | | for (var i = 0; i < baseProps.Count; i++) |
| | 32 | 58 | | newProps[i] = new LocalizedPropertyDescriptor(baseProps[i]); |
| | 24 | 59 | | return new PropertyDescriptorCollection(newProps); |
| | 16 | 60 | | } |
| | | 61 | | } |
| | | 62 | | } |