
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
772
|
Chapter 13: Reflection
{
Console.WriteLine("\t{0}", t.FullName);
}
}
}
The output of this method is shown here:
C:\CSharp Recipes 2nd Edition\Code\CSharpRecipes\bin\Debug\CSharpRecipes.exe has
serializable types:
CSharpRecipes.ExceptionHandling+RemoteComponentException
CSharpRecipes.DelegatesEventsAnonymousMethods+HashtableEventHandler
CSharpRecipes.Collections+MaxMinSizeDictionary`2
CSharpRecipes.Collections+MaxMinValueHashtable
CSharpRecipes.DataStructsAndAlgorithms+DblQueue`1
CSharpRecipes.ClassAndStructs+DeepClone
CSharpRecipes.ClassAndStructs+MultiClone
CSharpRecipes.ClassAndStructs+Serializer`1
Discussion
A type may be marked as serializable using the SerializableAttribute attribute.
Testing for the
SerializableAttribute attribute on a type can turn into a fair amount
of work. This is because the
SerializableAttribute is a magic attribute that the C#
compiler actually strips off your code at compile time. Using ildasm you will see that
this custom attribute just isn’t there—normally you see a
.custom entry for each cus-
tom attribute, but not with
SerializableAttribute. The C# compiler removes it, and
instead sets a flag in the metadata of the class. In source code, it looks like a custom
attribute, but it compiles into one of a small set of attributes that gets a special