meta data and attribute
-
Yes, they can be reflected. Recently I'm working on a project implementing plug-in architecture and this is the way I identify plug-ins.
Thanks natsuyaki, 1. Sorry my English is not good. You mean both .Net built-in and user defined attribute exist in the final meta data part of assembly, even for the method level attribute? 2. How do you find the final values? Using reflector tool or? Reflector tool I mean, http://www.aisto.com/roeder/dotnet/[^] regards, George
-
Thanks natsuyaki, 1. Sorry my English is not good. You mean both .Net built-in and user defined attribute exist in the final meta data part of assembly, even for the method level attribute? 2. How do you find the final values? Using reflector tool or? Reflector tool I mean, http://www.aisto.com/roeder/dotnet/[^] regards, George
-
My English is not so good too... ;P 1. class level attributes exist in meta data, method level unkonown... 2. Using Type.GetCustomAttribute() to get custom attribute at runtime. Or the tool ILDasm in .NET SDK or others.
Great natsuyaki! How to use ILDasm to read meta data and attributes? I only find IL for each method/class from this tool. regards, George
-
My English is not so good too... ;P 1. class level attributes exist in meta data, method level unkonown... 2. Using Type.GetCustomAttribute() to get custom attribute at runtime. Or the tool ILDasm in .NET SDK or others.
-
Great natsuyaki! How to use ILDasm to read meta data and attributes? I only find IL for each method/class from this tool. regards, George
-
You can write and compile an assembly with custom and built-in class/method level attributes. See if they exist in meta data using ILDasm.
Thanks natsuyaki! I think you monitor the attribute in IL using ILDasm tool, not the below tool, right? http://www.aisto.com/roeder/dotnet/ (the tool has a confusing name relfector, which makes me confused in the discussion context) regards, George
-
If there is a custom attribute. It displays ".custom instance void[xxx]xxxxxx.xxxxAtribute::cctor()=........."
Great natsuyaki! How to identify which parts of IL code are dealing with attribute definition? Any fields or keywords in IL identify? regards, George
-
Thanks natsuyaki! I think you monitor the attribute in IL using ILDasm tool, not the below tool, right? http://www.aisto.com/roeder/dotnet/ (the tool has a confusing name relfector, which makes me confused in the discussion context) regards, George
-
Thanks natsuyaki, 1. Yes, it is using relection, but not using the tool I quoted. From this tool, could you see any attributes? 2. Any comments to, http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2547385[^] regards, George
-
Thanks natsuyaki, 1. Yes, it is using relection, but not using the tool I quoted. From this tool, could you see any attributes? 2. Any comments to, http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2547385[^] regards, George
The following IL code is retrieved by ILDasm: class with SerializableAttribute:
.class public auto ansi serializable beforefieldinit ClassLibrary2.Class1 extends [mscorlib]System.Object { } // end of class ClassLibrary2.Class1
method with ObsoleteAttribute:.method public hidebysig instance void s() cil managed { .custom instance void [mscorlib]System.ObsoleteAttribute::.ctor() = ( 01 00 00 00 ) // code size 2 (0x2) .maxstack 8 IL_0000: nop IL_0001: ret } // end of method Class1::s
-
The following IL code is retrieved by ILDasm: class with SerializableAttribute:
.class public auto ansi serializable beforefieldinit ClassLibrary2.Class1 extends [mscorlib]System.Object { } // end of class ClassLibrary2.Class1
method with ObsoleteAttribute:.method public hidebysig instance void s() cil managed { .custom instance void [mscorlib]System.ObsoleteAttribute::.ctor() = ( 01 00 00 00 ) // code size 2 (0x2) .maxstack 8 IL_0000: nop IL_0001: ret } // end of method Class1::s
Thanks natsuyaki, 1. It is great! Are there any tool for us to use to retrieve readable meta data and attribute information without using ILDasm tool? 2. Generally speaking, from what pattern, could you identify a part of code in IL is dealing with attribute -- like the following code,
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor() = ( 01 00 00 00 )
regards, George
-
Thanks natsuyaki, 1. It is great! Are there any tool for us to use to retrieve readable meta data and attribute information without using ILDasm tool? 2. Generally speaking, from what pattern, could you identify a part of code in IL is dealing with attribute -- like the following code,
.custom instance void [mscorlib]System.ObsoleteAttribute::.ctor() = ( 01 00 00 00 )
regards, George
1. i don't really know, maybe the tool you mentioned can. 2. I wrote a custom attribute PuginAttribute. All the plugins must add this attribute. So, I can get it at runtime by GetCustomAttribute(), if exists, that mean this is a plugin.
[Plugin(true)] public class SamplePlugin:IPlugin { ..... ....
IL code would be displayed like this:.custom instance void [XXXX]aaa.bbb.ccc.PluginAttribute::.ctor(bool) = ( 01 00 00 00 )
-
1. i don't really know, maybe the tool you mentioned can. 2. I wrote a custom attribute PuginAttribute. All the plugins must add this attribute. So, I can get it at runtime by GetCustomAttribute(), if exists, that mean this is a plugin.
[Plugin(true)] public class SamplePlugin:IPlugin { ..... ....
IL code would be displayed like this:.custom instance void [XXXX]aaa.bbb.ccc.PluginAttribute::.ctor(bool) = ( 01 00 00 00 )
Thanks natsuyaki, 1. Looks like attribute will be treated as a private class in IL? 2. I think not all built-in attributes will be left in final IL, what kinds of built-in attributes will be in final IL, could you list some please? :-) regards, George
-
Thanks natsuyaki, 1. Looks like attribute will be treated as a private class in IL? 2. I think not all built-in attributes will be left in final IL, what kinds of built-in attributes will be in final IL, could you list some please? :-) regards, George
1.some like that 2.some attributes reprent for "mark",and some for "deal". That means, some attributes are use for comment the content, some for the compiler that the content will be processed by the mean mentioned in the attributes. So, some keep there and some disappeared. This is my point of view. For the precise definition, please view msdn.
-
1.some like that 2.some attributes reprent for "mark",and some for "deal". That means, some attributes are use for comment the content, some for the compiler that the content will be processed by the mean mentioned in the attributes. So, some keep there and some disappeared. This is my point of view. For the precise definition, please view msdn.
Thanks natsuyaki, I agree with your points. Could you list some of the attribute names which do not disappear in IL please? Sorry, my knowledge of attribute is limited. :-) regards, George
-
Thanks natsuyaki, I agree with your points. Could you list some of the attribute names which do not disappear in IL please? Sorry, my knowledge of attribute is limited. :-) regards, George
That's a big work to do.... You may be interested in this book: Applied .Net Attributes by Jason Bock Sorry, here we go. And this could also help:http://www.codeproject.com/KB/cs/attributes.aspx
modified on Monday, May 12, 2008 4:30 AM
-
That's a big work to do.... You may be interested in this book: Applied .Net Attributes by Jason Bock Sorry, here we go. And this could also help:http://www.codeproject.com/KB/cs/attributes.aspx
modified on Monday, May 12, 2008 4:30 AM
Thanks natsuyaki, The link you provided can not be opened, could you double check please? :-) regards, George