CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

Framework Glue: Metadata

I occasionally hear or read people asking about metadata and what is it in the .Net framework.

1. Metadata describes information found in all managed objects.  Properties and methods found in a type are described by the metadata table associated with that type.  Without metadata, the .Net framework wouldn’t be very useful.  Because the framework reads the metadata for a type, this allows VB written classes to be used by C# code, because it was complied to a common assembly language and has a common metadata table structure that the framework can read and understand and therefore utilize in another language.

2. Probably Sahil’s favorite: serialization.  Without metadata, serialization and deserialization of data wouldn’t be possible, I don’t think.  Mind you, I’m not incredibly knowledgable about serialization, I just understand what it does and know how to serialize things and get them back.  Metadata must be serialized into the stream so that you have some sort of map for what your object really is when you go to pull it back out of the stream.  Metadata provides a map for the entire instance.  If you have a System.DateTime object you want to serialize, you aren’t just serializing the DateTime object, you have to serialize System.Object as well, because its part of the instance.  Metadata takes care of all that descriptive stuff so we don’t have to worry about any of that.  You’ll have to get somebody else to explain to you the inner workings of exactly how metadata is used in serialization.  Common sense tells you though, that just the nature of serialization and what takes place relies heavily on metadata.

3. Intellisense would not exist without metadata.  The magic forces of intellisense read the metadata of an assemblies types and use that to provide us, in the IDE, with wonderful bits of information about the types, its methods and properties, available to us.  Intellisense is really a wonderful thing, especially in 2005 IDE.

4. My favorite part of the framework: Garbage collection.  The GC uses metadata to figure out what objects another object can refer to, and if that object is currently able to be used.  The CLR uses metadata to figure out where objects exist in memory and just how much space they take up.  Without metadata, the GC wouldn’t know the start and end of an objects address space.

5. How is metadata most commonly used directly by us developers?  Reflection.  Reflection is the dynamic examination of an object’s metadata.  I use reflection to build very large datatables from the structure of an object and its properties without having to hardcode anything.  This saves me thousands of lines of code, and is all made possible because of metadata.  Reflection deserves its own topic, and you can probably google it and find quite a bit more information that I’ll provide anytime soon.

So, there you have it.  That’s my opinion of what metadata is and what it does for me.  If I left something out or am completely wrong about something, I’m sure somebody out there will let me know.



Comments

TrackBack said:

Framework Glue: Metadata
# February 23, 2005 5:29 AM

Pedro Silva said:

And, metadata is used extensively in the Visual Studio 2005 Beta. The Distributed System Designers and Class Designer use metadata from the framework and other that's collected by the model for each designer to do their magic as well.
# February 23, 2005 8:45 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Raymond Lewallen

Working primarily in the public sector during his career, Raymond has designed and built several high profile enterprise level applications for all levels of the government. Raymond now works as a solutions architect for EMC. Raymond is an agile coach, Microsoft MVP C# and also president of the Oklahoma City Developers Group and Oklahoma Agile Developers Group. Raymond spends a lot of his time learning and teaching such things as Test Driven Development, Domain Driven Design, Design Patterns and Extreme Programming practices and principles, to name a few. Raymond is also an advocate of Alt.Net. Raymond is primarily a framework guy, so don't ask him anything about UI :) Check out Devlicio.us!