protected virtual void InitializeAssembly (AssemblyDefinition assembly)
{
MarkAssembly (assembly);
- foreach (TypeDefinition type in assembly.MainModule.Types) {
- if (!Annotations.IsMarked (type))
- continue;
+ foreach (TypeDefinition type in assembly.MainModule.Types)
InitializeType (type);
- }
}
void InitializeType (TypeDefinition type)
{
+ if (type.HasNestedTypes) {
+ foreach (var nested in type.NestedTypes)
+ InitializeType (nested);
+ }
+
+ if (!Annotations.IsMarked (type))
+ return;
+
MarkType (type);
if (type.HasFields)
InitializeFields (type);
if (type.HasMethods)
InitializeMethods (type.Methods);
-
- if (type.HasNestedTypes) {
- foreach (var nested in type.NestedTypes) {
- if (Annotations.IsMarked (nested))
- InitializeType (nested);
- }
- }
}
void InitializeFields (TypeDefinition type)
MarkFields (type, type.IsEnum);
if (type.HasInterfaces) {
- foreach (TypeReference iface in type.Interfaces)
- MarkType (iface);
+ foreach (var iface in type.Interfaces)
+ MarkType (iface.InterfaceType);
}
if (type.HasMethods) {
MarkMethodsIf (type.Methods, IsVirtualAndHasPreservedParent);
MarkMethodsIf (type.Methods, IsStaticConstructorPredicate);
+ MarkMethodsIf (type.Methods, HasSerializationAttribute);
}
DoAdditionalTypeProcessing (type);
return method.IsConstructor && method.IsStatic;
}
+ static bool HasSerializationAttribute (MethodDefinition method)
+ {
+ if (!method.HasCustomAttributes)
+ return false;
+ foreach (var ca in method.CustomAttributes) {
+ var cat = ca.AttributeType;
+ if (cat.Namespace != "System.Runtime.Serialization")
+ continue;
+ switch (cat.Name) {
+ case "OnDeserializedAttribute":
+ case "OnDeserializingAttribute":
+ case "OnSerializedAttribute":
+ case "OnSerializingAttribute":
+ return true;
+ }
+ }
+ return false;
+ }
+
static bool IsSerializable (TypeDefinition td)
{
return (td.Attributes & TypeAttributes.Serializable) != 0;