Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
67 views
in Technique[技术] by (71.8m points)

c# - What is metadata in .NET?

I googled several sites to understand what metadata is in .NET and it means.

I'm still new to C# WPF desktop application programming. Back when I was web programming, there are meta tag in HTML code where we describe the site with titles, keywords and such. Is also similar in .NET application? I read wiki, and googled but all I get is conceptional explanation.

One describes "metadata is data that describes the state of the assembly and a detailed description of each type, attribute within the assembly". Is metadata just a concept or something physical like line of codes I typed in somewhere to describe my code? If so, do my commend becomes my metadata?

I read metadata is "Within the Common Language Runtime (CLR)", but I code only in C#, how can I code in CLR into the metadata? Is metadata a commend in CLR? How Can I change it.

MSDN wrote that metadata is binary information for software component of another language to understand it. I though only human needs description (commend) in English to understand what a block of code does. Software component simply executes whatever statement we wrote - what's is the need of the "binary" information. How can the compiler understand the meaning of my high level code to generate "Description of assembly"? If I write a program that convert currency, would the metadata auto-generated knowing the program is converting currency? Where is this intelligence?

I am completely confused.

question from:https://stackoverflow.com/questions/8861065/what-is-metadata-in-net

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since others already provided great explanatory answers, I'll just mention how you can view metadata yourself.

In your Microsoft SDK directory (most likely variations of C:Program FilesMicrosoft SDKsWindowsv7.0ABinNETFX 4.0 Tools) there's program called ildasm.exe - it's simple disassembler that allows you to view compiled .NET binaries.

You can build very simple console application and use ildasm.exe to view compiled contents. View/MetaInfo/Show! command (or simply Ctrl + M) will display metadata - you can check how they look like. Part of metadata from application printing Hello to console:

TypeDef #1 (02000002)
-------------------------------------------------------
TypDefName: Program  (02000002)
Flags     : [Public] [AutoLayout] [Class] [AnsiClass] [BeforeFieldInit](00100001)
Extends   : 01000001 [TypeRef] System.Object
Method #1 (06000001) [ENTRYPOINT]
-------------------------------------------------------
    MethodName: Main (06000001)
    Flags     : [Public] [Static] [HideBySig] [ReuseSlot]  (00000096)
    RVA       : 0x00002050
    ImplFlags : [IL] [Managed]  (00000000)
    CallCnvntn: [DEFAULT]
    ReturnType: Void
    1 Arguments
        Argument #1:  SZArray String
    1 Parameters
        (1) ParamToken : (08000001) Name : args flags: [none] (00000000)

Here you can see type definition (Program) and one of its methods (Main), which takes single input argument and returns void. This is naturally only part of metadata, even for simpliest programs there's a lot more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...