473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

C#-ILAsm custom attributes

Hello,

for some reason I need to use attributes in ILAsm code and read these
attributes in C# code. My problem is with the attribute declaration inside
ILAsm code. I know that I define any attribute by using ILasm's ".custom"
keyword but I do not understand how to initialize the attribute Value blob
when the attribute contains some fields. I just do not understand that
binary format:

..custom instance void MyAttribute::.ctor(bool) = (01 00 01 00 00)

(example taken from "Inside IL" by Serge Lidin, the attribute constructor
has only 1 parameter of type 'bool')

Lidin does not say anything on how the attrubute's constructor arguments
should be encoded (except of arguments of type 'string', he says that such
attributes should be represented by unicode hex data).

My questions:
- how do I encode any particular datatype (strings, ints, etc)?
- how do I encode attributes of custom types?
- how do I separate consecutive arguments in the argument list?

Thanks for any help,
Wiktor Zychla
Nov 16 '05 #1
4 2715
Wiktor Zychla wrote:
Hello,

for some reason I need to use attributes in ILAsm code and read these
attributes in C# code. My problem is with the attribute declaration inside
ILAsm code. I know that I define any attribute by using ILasm's ".custom"
keyword but I do not understand how to initialize the attribute Value blob
when the attribute contains some fields. I just do not understand that
binary format:

.custom instance void MyAttribute::.ctor(bool) = (01 00 01 00 00)

(example taken from "Inside IL" by Serge Lidin, the attribute constructor
has only 1 parameter of type 'bool')

Lidin does not say anything on how the attrubute's constructor arguments
should be encoded (except of arguments of type 'string', he says that such
attributes should be represented by unicode hex data).

My questions:
- how do I encode any particular datatype (strings, ints, etc)?
- how do I encode attributes of custom types?
- how do I separate consecutive arguments in the argument list?

Thanks for any help,
Wiktor Zychla


Why not create a dummy C# application with the attributes you require
applied, compile it and then use ILDASM to see what was generated?
Nov 16 '05 #2
Wiktor,

I'm curious, why are you declaring these in IL?

For the format of declaring an attribute, check (watch for line wrap):

http://jilc.sourceforge.net/ecma_p2_...m_Attributes_1

Here is the format for the blob used to pass parameters to the
constructor:

http://jilc.sourceforge.net/ecma_p2_...m_Attributes_2

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wiktor Zychla" <us**@nospam.com.eu> wrote in message
news:uc**************@TK2MSFTNGP10.phx.gbl...
Hello,

for some reason I need to use attributes in ILAsm code and read these
attributes in C# code. My problem is with the attribute declaration inside
ILAsm code. I know that I define any attribute by using ILasm's ".custom"
keyword but I do not understand how to initialize the attribute Value blob
when the attribute contains some fields. I just do not understand that
binary format:

.custom instance void MyAttribute::.ctor(bool) = (01 00 01 00 00)

(example taken from "Inside IL" by Serge Lidin, the attribute constructor
has only 1 parameter of type 'bool')

Lidin does not say anything on how the attrubute's constructor arguments
should be encoded (except of arguments of type 'string', he says that such
attributes should be represented by unicode hex data).

My questions:
- how do I encode any particular datatype (strings, ints, etc)?
- how do I encode attributes of custom types?
- how do I separate consecutive arguments in the argument list?

Thanks for any help,
Wiktor Zychla

Nov 16 '05 #3
> I'm curious, why are you declaring these in IL?

practical part of my PhD research.

thanks for your help.

Wiktor Zychla
Nov 16 '05 #4
Wiktor,

FYI, the Whidbey version of IL(D)ASM supports new, typed syntax for
the attribute data, so you no longer have to work with the raw blob
format.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Doug Holland | last post by:
Often you see code where an empty interface is used to indicate something about the class that realizes it. In the .NET world this can be done with custom attributes too, so which is better: ...
3
by: xAvailx | last post by:
I apologize ahead of time for the long post... Background: Working on a CRM type custom application. The application is for an event management company. The company will provide the application...
8
by: nicolas.sanguinetti | last post by:
Hi, I want to add custom attributes to my xhtml documents to use with my DOM scripts. For example, I want to have some tags -say, the <h1>- have an attribute and a . The thing is that I also...
1
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are...
3
by: Edward Diener | last post by:
I understand the syntax of custom attributes, but I have no idea what they are supposed to do. Anyone care to give me a clue as to their functionality ?
1
by: Tamas Demjen | last post by:
I started to experiment with VC++ 2005 Beta1. So far everything went fine, and already have a working project, but soon I realized that the compiler was ancient (not supporting half of the C++/CLI...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
2
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
5
by: =?Utf-8?B?cGFnYXRlcw==?= | last post by:
Hello All, I am sure that I am just overlooking something, but here's something I can't quite get right... I want to be able to get the value of a parameter of an unknown custom attribute at...
1
camel
by: camel | last post by:
Apologies if foolish question, but I somewhat expected Custom Attributes (i.e. inheriting from System.Attribute) decorating class properties to come through via WSDL to the proxy the same as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.