Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET .resx files: why does name attribute often start with >>

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

like image 736
Peter B Avatar asked Apr 30 '14 07:04

Peter B


People also ask

What is a .resx file and how do you use it?

The . resx resource file format consists of XML entries that specify objects and strings inside XML tags. One advantage of a . resx file is that when opened with a text editor (such as Notepad) it can be written to, parsed, and manipulated.

What is .resx file in C#?

Net Resource (. resx) files are a monolingual file format used in Microsoft . Net Applications. The . resx resource file format consists of XML entries, which specify objects and strings inside XML tags.

How do I open a .resx file?

Navigate to resources from File Structure Open a . resx file in the XML (Text) editor. Press Ctrl+Alt+F or choose ReSharper | Windows | File Structure from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.

What is meta Resourcekey?

The meta:resourcekey syntax allows you use declarative syntax for Implicit Resource expressions. This is used when localizing a site for international use.


1 Answers

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.

like image 62
Hans Passant Avatar answered Sep 22 '22 14:09

Hans Passant