Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I apologize for the VB.NET code, my C# is a bit rusty... But you'll get the idea, right?</p> <p>First of all, create a new class: <code>LocalizedPropertyDescriptor</code>, which inherits <code>PropertyDescriptor</code>. Override the <code>DisplayName</code> property like this:</p> <pre><code>Public Overrides ReadOnly Property DisplayName() As String Get Dim BaseValue As String = MyBase.DisplayName Dim Translated As String = Some.ResourceManager.GetString(BaseValue) If String.IsNullOrEmpty(Translated) Then Return MyBase.DisplayName Else Return Translated End If End Get End Property </code></pre> <p><code>Some.ResourceManager</code> is the ResourceManager of the resource file that contains your translations.</p> <p>Next, implement <code>ICustomTypeDescriptor</code> in the class with the localized properties, and override the <code>GetProperties</code> method:</p> <pre><code>Public Function GetProperties() As PropertyDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetProperties Dim baseProps As PropertyDescriptorCollection = TypeDescriptor.GetProperties(Me, True) Dim LocalizedProps As PropertyDescriptorCollection = New PropertyDescriptorCollection(Nothing) Dim oProp As PropertyDescriptor For Each oProp In baseProps LocalizedProps.Add(New LocalizedPropertyDescriptor(oProp)) Next Return LocalizedProps End Function </code></pre> <p>You can now use the 'DisplayName` attribute to store a reference to a value in a resource file...</p> <pre><code>&lt;DisplayName("prop_description")&gt; _ Public Property Description() As String </code></pre> <p><code>prop_description</code> is the key in the resource file.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload