471,348 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

hex type values

If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="joe")]
where stringVal is a string C# generates the name\value pair using hex values
01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
I've determined 54 is a delimiter between properties and the next value OE
represents the string type. Is there a complete table of hex values and their
map to all the types or a particular System.Type method I could use to get
this value?
Any documentation on this hex representation would also be helpful.

thanks - Jim
Jun 27 '08 #1
5 2141
jim <ji*@discussions.microsoft.comwrote:
If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="joe")]
where stringVal is a string C# generates the name\value pair using hex values
01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
I've determined 54 is a delimiter between properties and the next value OE
represents the string type. Is there a complete table of hex values and their
map to all the types or a particular System.Type method I could use to get
this value?
Any documentation on this hex representation would also be helpful.
It's not clear to me what exactly is genering the string. You say it's
C#, but the C# compiler isn't going to be doing this for your own
custom attribute value.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #2
when running ILDASM on the following program created by C# you can see
the attribute values on the program class:

using System;
using System.Reflection;

namespace ConsoleApplication8
{
class MyAttribute : Attribute
{
private string sval;
public string stringVal
{
get { return sval; }
set { sval = value; }
}
}
[My(stringVal="joe")]
class Program
{
static void Main(string[] args)
{
}
}
}
"Jon Skeet [C# MVP]" wrote:
jim <ji*@discussions.microsoft.comwrote:
If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="joe")]
where stringVal is a string C# generates the name\value pair using hex values
01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
I've determined 54 is a delimiter between properties and the next value OE
represents the string type. Is there a complete table of hex values and their
map to all the types or a particular System.Type method I could use to get
this value?
Any documentation on this hex representation would also be helpful.

It's not clear to me what exactly is genering the string. You say it's
C#, but the C# compiler isn't going to be doing this for your own
custom attribute value.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #3
[MyAttr(stringVal="joe")]

Dont know, but might it be unicode? This looks like a explanation...

In the current implementation at least, strings take up 20+(n/2)*4
bytes (rounding the value of n/2 down), where n is the number of
characters in the string. The string type is unusual in that the size
of the object itself varies.

Found at http://www.yoda.arachsys.com/csharp/strings.html

//CY
Jun 27 '08 #4
jim <ji*@discussions.microsoft.comwrote:
when running ILDASM on the following program created by C# you can see
the attribute values on the program class:
Well, you can see the IL representation - but why is that important to
you? Surely the important point is getting the attribute value in code,
which you do with reflection, where the IL representation doesn't
matter at all.

The IL representation will be documented in ECMA 335, but very few
situations will really need to know about it.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #5
jim wrote:
If I assign an attribute using property name/value pairs such as
[MyAttr(stringVal="joe")]
where stringVal is a string C# generates the name\value pair using hex values
01 00 01 00 54 0E 09 73 74 72 69 6E 67 56 61 6C 03 6A 6F 65.
I've determined 54 is a delimiter between properties and the next value OE
represents the string type. Is there a complete table of hex values and their
map to all the types or a particular System.Type method I could use to get
this value?
Any documentation on this hex representation would also be helpful.

thanks - Jim

Well, FWIW it's obvious enough that '09 73 74 72 69 6E 67 56 61 6C' is the
length of "stringVal" followed by the string itself (in 8-bit ASCII) and '03 6A
6F 65' is the length of "joe" followed by the string itself. But why in the
world do you care?

HTH,
-rick-
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by BigMan | last post: by
51 posts views Thread by jacob navia | last post: by
6 posts views Thread by M.A. Oude Kotte | last post: by
7 posts views Thread by Martin Robins | last post: by
10 posts views Thread by Tomás | last post: by
10 posts views Thread by kar1107 | last post: by
669 posts views Thread by Xah Lee | last post: by
7 posts views Thread by Harris | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.