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.
Posted
02-23-2005 7:14 AM
by
Raymond Lewallen