Question

In many .resx files I come across something like this:

<data name="&gt;&gt;OurLabel.Name" xml:space="preserve">
  <value>OurLabel</value>
</data>

My question is: why does the attribute name in many cases - but not always - start with &gt;&gt;?

Was it helpful?

Solution

You found this in the .resx file for a Winforms form with its Localizable property set to True. &gt; is the xml encoding for the > character so the property value name that is getting saved is ">>OurLabel.Name".

Other properties that you'll see treated like this are Type, Parent, ZOrder.

What is special about them is that they are design-time properties. Extra ones that are added by the designer for a control. The problem with the designer adding these properties is that they can cause ambiguity. The best example I can think of is intentionally causing such an ambiguity:

using System;
using System.ComponentModel;
using System.Windows.Forms;

class MyLabel : Label {
    [Localizable(true)]
    public string Type { get; set; }
}

Drop this one on a form and now there are two Type properties for the control. You'll see them back in the .resx file like this:

 <data name="myLabel1.Type" xml:space="preserve">
   <value>Example</value>
 </data>
 <data name="&gt;&gt;myLabel1.Type" xml:space="preserve">
   <value>MyLabel, WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</value>
 </data>

Note the difference between "myLabel1.Type" and ">>myLabel1.Type". Problem solved.

You'll also see the "$this." prefix used. It disambiguates between the name of a property of the form and the name of a control on the form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top