The text of a <value> means nothing alone: the type and mimetype attributes of its data entry say what it is. The reader applies these rules in order (they are those of ResXDataNode):
The rules, in order
| # | If the entry has… | The value is… |
|---|---|---|
| 1 | a mimetype | read by the mimetype’s rule (the next table) |
| 2 | no type and no mimetype | a string: the text of the value |
| 3 | the type System.Resources.ResXNullRef | null |
| 4 | the type System.Byte[] (with mscorlib or System.Private.CoreLib as its assembly) | a byte array: the value is base64 |
| 5 | the type System.Resources.ResXFileRef | the contents of a file, see below; the value is path;Type[;encoding] |
| 6 | any other type | made by the type’s TypeConverter from the text of the value (invariant culture); if the type has no converter that reads text, the value is null |
| Mimetype | Value | Result |
|---|---|---|
application/x-microsoft.net.object.binary.base64 | base64 of a BinaryFormatter stream | the deserialised object (the type attribute is not used) |
application/x-microsoft.net.object.bytearray.base64 | base64 of raw bytes | the object that the converter of type makes from the byte array (System.Drawing.Icon, System.Drawing.Bitmap, System.Drawing.Image, System.Windows.Forms.Cursor and the like); with no usable type the result is null |
application/x-microsoft.net.object.soap.base64 | base64 of a SOAP-formatted serialisation | the deserialised object (SoapFormatter, no longer available in current .NET) |
| anything else | — | null; the viewer reports the mimetype |
Base64 is the standard alphabet with = padding; white space (spaces, line breaks) is ignored. The writers break the base64 into lines of 80 characters.
File references
A ResXFileRef keeps a resource in its own file instead of inside the .resx, so that a designer can edit the picture or the text with another tool. The value is path;TypeName or path;TypeName;encoding, for example ..\Resources\logo.png;System.Drawing.Bitmap, System.Drawing or notes.txt;System.String, mscorlib;utf-8. If the path contains a semicolon or a double quote it is written in double quotes: "..\a;b\pic.png";System.Drawing.Bitmap, System.Drawing. The parts are cut at the first ; (outside the quotes) for the path, then at the next ; for the type and an optional encoding name. The path is relative to the .resx file. When the resource is built, the file is read: as text in the given encoding for System.String, as bytes for System.Byte[], as a stream for System.IO.MemoryStream, and by the constructor of the type that takes a Stream for the others (Bitmap, Icon, Cursor); a .ico that is to be a Bitmap is read as an icon and converted so that its transparency survives. The file’s contents then travel in the compiled resources, not in the .resx.
Images, icons and other binary files
- As a byte array with a type:
type="System.Drawing.Icon, System.Drawing" mimetype="…bytearray.base64": the base64 is the bytes of the.icofile. This is what the Windows Forms designer writes for an icon and for most bitmaps in newer files. - As a serialised object:
mimetype="…binary.base64"with no type: the base64 is a BinaryFormatter stream whose class isSystem.Drawing.Bitmap(memberData, the bytes of the picture file: PNG, BMP, GIF, JPEG),System.Drawing.Icon(memberIconData), orSystem.Windows.Forms.ImageListStreamer(memberData, the bytes of the image list in its Windows form, startingMSFt). The viewer reads the stream and shows the picture bytes as a file that can be opened. - As a byte array:
type="System.Byte[], mscorlib": the raw bytes of any file (a sound, a database, a PDF). - As a file reference: above.
The text forms of common types
A typed value with no mimetype is the text a TypeConverter reads in the invariant culture. These are the forms of the types that fill most Windows Forms files:
| Type | Text form | Example |
|---|---|---|
System.Drawing.Point, Size | x, y; width, height | 12, 20 |
System.Drawing.PointF, SizeF | floating point numbers separated by commas | 6, 13 |
System.Drawing.Rectangle | x, y, width, height | 0, 0, 100, 50 |
System.Drawing.Color | a known colour name, a system colour name, or A, R, G, B / R, G, B as numbers, or #RRGGBB | Control, 255, 128, 0 |
System.Drawing.Font | Family, Size[unit][, style=…] | Microsoft Sans Serif, 8.25pt, Tahoma, 9pt, style=Bold |
System.Windows.Forms.Padding, Margin | all or left, top, right, bottom | 3, 3, 3, 3 |
System.Boolean, Int32, Int64, Double, Decimal | True/False; invariant numbers | True, 42 |
an enumeration (System.Windows.Forms.DockStyle, AnchorStyles, ContentAlignment, FormStartPosition, ImeMode, RightToLeft, System.CodeDom.MemberAttributes) | the member name; for flags, names separated by a comma and a space | Fill, Top, Left, Private, CenterScreen |
System.Globalization.CultureInfo | a culture name | en-US |
Not described
Known, not yet covered
- Reference: the text forms of the rest of the types (
ToolStripItemDisplayStyle,ListViewItem,TreeNode, and the many types of third-party controls) are not listed; each has the converter its authors wrote. - Reference: the layout of the Windows ImageList stream (
MSFt) is not described.
Unknown
- Reference: how every version of .NET treats a
mimetypeentry when BinaryFormatter is disabled was not tested: the documentation says the reader then needs theSystem.Resources.Extensionspackage, which the tooling page names.