Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. meta data and attribute

meta data and attribute

Scheduled Pinned Locked Moved C#
csharpdotnetquestion
19 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    George_George
    wrote on last edited by
    #1

    Hello everyone, Two questions related to meta data and attribute, 1. .Net built-in and user defined attribute are both defined in meta data portion of assembly or not? In my past experience, I think method/class level attribute is only used to facilitate the method/class IL generation, and will not exist in final assembly file. Any comments? 2. If .Net built-in and user defined attribute exist in the final meta data part of assembly, is it possible to use reflector to see them? (I have tried but can not find.) thanks in advance, George

    N 1 Reply Last reply
    0
    • G George_George

      Hello everyone, Two questions related to meta data and attribute, 1. .Net built-in and user defined attribute are both defined in meta data portion of assembly or not? In my past experience, I think method/class level attribute is only used to facilitate the method/class IL generation, and will not exist in final assembly file. Any comments? 2. If .Net built-in and user defined attribute exist in the final meta data part of assembly, is it possible to use reflector to see them? (I have tried but can not find.) thanks in advance, George

      N Offline
      N Offline
      natsuyaki
      wrote on last edited by
      #2

      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.

      G 1 Reply Last reply
      0
      • N natsuyaki

        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.

        G Offline
        G Offline
        George_George
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • G George_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

          N Offline
          N Offline
          natsuyaki
          wrote on last edited by
          #4

          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.

          G N 2 Replies Last reply
          0
          • N natsuyaki

            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.

            G Offline
            G Offline
            George_George
            wrote on last edited by
            #5

            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

            N 1 Reply Last reply
            0
            • N natsuyaki

              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.

              N Offline
              N Offline
              natsuyaki
              wrote on last edited by
              #6

              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.

              G 1 Reply Last reply
              0
              • G George_George

                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

                N Offline
                N Offline
                natsuyaki
                wrote on last edited by
                #7

                If there is a custom attribute. It displays ".custom instance void[xxx]xxxxxx.xxxxAtribute::cctor()=........."

                G 1 Reply Last reply
                0
                • N natsuyaki

                  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.

                  G Offline
                  G Offline
                  George_George
                  wrote on last edited by
                  #8

                  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

                  N 1 Reply Last reply
                  0
                  • N natsuyaki

                    If there is a custom attribute. It displays ".custom instance void[xxx]xxxxxx.xxxxAtribute::cctor()=........."

                    G Offline
                    G Offline
                    George_George
                    wrote on last edited by
                    #9

                    Great natsuyaki! How to identify which parts of IL code are dealing with attribute definition? Any fields or keywords in IL identify? regards, George

                    1 Reply Last reply
                    0
                    • G George_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

                      N Offline
                      N Offline
                      natsuyaki
                      wrote on last edited by
                      #10

                      :) but it's really using reflection.~

                      G 1 Reply Last reply
                      0
                      • N natsuyaki

                        :) but it's really using reflection.~

                        G Offline
                        G Offline
                        George_George
                        wrote on last edited by
                        #11

                        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

                        N 1 Reply Last reply
                        0
                        • G George_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

                          N Offline
                          N Offline
                          natsuyaki
                          wrote on last edited by
                          #12

                          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

                          G 1 Reply Last reply
                          0
                          • N natsuyaki

                            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

                            G Offline
                            G Offline
                            George_George
                            wrote on last edited by
                            #13

                            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

                            N 1 Reply Last reply
                            0
                            • G George_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

                              N Offline
                              N Offline
                              natsuyaki
                              wrote on last edited by
                              #14

                              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 )

                              G 1 Reply Last reply
                              0
                              • N natsuyaki

                                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 )

                                G Offline
                                G Offline
                                George_George
                                wrote on last edited by
                                #15

                                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

                                N 1 Reply Last reply
                                0
                                • G George_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

                                  N Offline
                                  N Offline
                                  natsuyaki
                                  wrote on last edited by
                                  #16

                                  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.

                                  G 1 Reply Last reply
                                  0
                                  • N natsuyaki

                                    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.

                                    G Offline
                                    G Offline
                                    George_George
                                    wrote on last edited by
                                    #17

                                    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

                                    N 1 Reply Last reply
                                    0
                                    • G George_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

                                      N Offline
                                      N Offline
                                      natsuyaki
                                      wrote on last edited by
                                      #18

                                      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

                                      G 1 Reply Last reply
                                      0
                                      • N natsuyaki

                                        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

                                        G Offline
                                        G Offline
                                        George_George
                                        wrote on last edited by
                                        #19

                                        Thanks natsuyaki, The link you provided can not be opened, could you double check please? :-) regards, George

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups