5 // Jb Evain (jbevain@gmail.com)
8 // (C) 2007 Novell, Inc.
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
37 namespace Mono.Linker.Steps {
39 public class MarkStep : IStep {
41 protected LinkContext _context;
42 protected Queue _methods;
43 protected ArrayList _virtual_methods;
45 public AnnotationStore Annotations {
46 get { return _context.Annotations; }
51 _methods = new Queue ();
52 _virtual_methods = new ArrayList ();
55 public virtual void Process (LinkContext context)
65 foreach (AssemblyDefinition assembly in _context.GetAssemblies ())
66 InitializeAssembly (assembly);
69 protected virtual void InitializeAssembly (AssemblyDefinition assembly)
71 MarkAssembly (assembly);
72 foreach (TypeDefinition type in assembly.MainModule.Types) {
73 if (!Annotations.IsMarked (type))
76 InitializeType (type);
80 void InitializeType (TypeDefinition type)
85 InitializeFields (type);
87 InitializeMethods (type.Methods);
89 if (type.HasNestedTypes) {
90 foreach (var nested in type.NestedTypes) {
91 if (Annotations.IsMarked (nested))
92 InitializeType (nested);
97 void InitializeFields (TypeDefinition type)
99 foreach (FieldDefinition field in type.Fields)
100 if (Annotations.IsMarked (field))
104 void InitializeMethods (ICollection methods)
106 foreach (MethodDefinition method in methods)
107 if (Annotations.IsMarked (method))
108 EnqueueMethod (method);
114 throw new InvalidOperationException ("No entry methods");
116 while (!QueueIsEmpty ()) {
118 ProcessVirtualMethods ();
124 while (!QueueIsEmpty ()) {
125 MethodDefinition method = (MethodDefinition) _methods.Dequeue ();
126 Annotations.Push (method);
127 ProcessMethod (method);
134 return _methods.Count == 0;
137 protected virtual void EnqueueMethod (MethodDefinition method)
139 _methods.Enqueue (method);
142 void ProcessVirtualMethods ()
144 foreach (MethodDefinition method in _virtual_methods)
145 ProcessVirtualMethod (method);
148 void ProcessVirtualMethod (MethodDefinition method)
150 IList overrides = Annotations.GetOverrides (method);
151 if (overrides == null)
154 foreach (MethodDefinition @override in overrides)
155 ProcessOverride (@override);
158 void ProcessOverride (MethodDefinition method)
160 if (!Annotations.IsMarked (method.DeclaringType))
163 if (Annotations.IsProcessed (method))
166 if (Annotations.IsMarked (method))
170 ProcessVirtualMethod (method);
173 void MarkMarshalSpec (IMarshalInfoProvider spec)
175 if (!spec.HasMarshalInfo)
178 var marshaler = spec.MarshalInfo as CustomMarshalInfo;
179 if (marshaler == null)
182 MarkType (marshaler.ManagedType);
185 void MarkCustomAttributes (ICustomAttributeProvider provider)
187 if (!provider.HasCustomAttributes)
190 foreach (CustomAttribute ca in provider.CustomAttributes)
191 MarkCustomAttribute (ca);
194 protected virtual void MarkCustomAttribute (CustomAttribute ca)
196 MarkMethod (ca.Constructor);
198 MarkCustomAttributeArguments (ca);
200 TypeReference constructor_type = ca.Constructor.DeclaringType;
201 TypeDefinition type = constructor_type.Resolve ();
203 throw new ResolutionException (constructor_type);
205 MarkCustomAttributeProperties (ca, type);
206 MarkCustomAttributeFields (ca, type);
209 protected void MarkSecurityDeclarations (ISecurityDeclarationProvider provider)
211 // most security declarations are removed (if linked) but user code might still have some
212 // and if the attribtues references types then they need to be marked too
213 if ((provider == null) || !provider.HasSecurityDeclarations)
216 foreach (var sd in provider.SecurityDeclarations)
217 MarkSecurityDeclaration (sd);
220 protected virtual void MarkSecurityDeclaration (SecurityDeclaration sd)
222 if (!sd.HasSecurityAttributes)
225 foreach (var sa in sd.SecurityAttributes)
226 MarkSecurityAttribute (sa);
229 protected virtual void MarkSecurityAttribute (SecurityAttribute sa)
231 TypeReference security_type = sa.AttributeType;
232 TypeDefinition type = security_type.Resolve ();
234 throw new ResolutionException (security_type);
236 MarkType (security_type);
237 MarkSecurityAttributeProperties (sa, type);
238 MarkSecurityAttributeFields (sa, type);
241 protected void MarkSecurityAttributeProperties (SecurityAttribute sa, TypeDefinition attribute)
243 if (!sa.HasProperties)
246 foreach (var named_argument in sa.Properties)
247 MarkCustomAttributeProperty (named_argument, attribute);
250 protected void MarkSecurityAttributeFields (SecurityAttribute sa, TypeDefinition attribute)
255 foreach (var named_argument in sa.Fields)
256 MarkCustomAttributeField (named_argument, attribute);
259 protected void MarkCustomAttributeProperties (CustomAttribute ca, TypeDefinition attribute)
261 if (!ca.HasProperties)
264 foreach (var named_argument in ca.Properties)
265 MarkCustomAttributeProperty (named_argument, attribute);
268 protected void MarkCustomAttributeProperty (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
270 PropertyDefinition property = GetProperty (attribute, namedArgument.Name);
271 if (property != null)
272 MarkMethod (property.SetMethod);
274 MarkIfType (namedArgument.Argument);
277 PropertyDefinition GetProperty (TypeDefinition type, string propertyname)
279 while (type != null) {
280 PropertyDefinition property = type.Properties.FirstOrDefault (p => p.Name == propertyname);
281 if (property != null)
284 type = type.BaseType != null ? ResolveTypeDefinition (type.BaseType) : null;
290 protected void MarkCustomAttributeFields (CustomAttribute ca, TypeDefinition attribute)
295 foreach (var named_argument in ca.Fields)
296 MarkCustomAttributeField (named_argument, attribute);
299 protected void MarkCustomAttributeField (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
301 FieldDefinition field = GetField (attribute, namedArgument.Name);
305 MarkIfType (namedArgument.Argument);
308 FieldDefinition GetField (TypeDefinition type, string fieldname)
310 while (type != null) {
311 FieldDefinition field = type.Fields.FirstOrDefault (f => f.Name == fieldname);
315 type = type.BaseType != null ? ResolveTypeDefinition (type.BaseType) : null;
321 void MarkCustomAttributeArguments (CustomAttribute ca)
323 if (!ca.HasConstructorArguments)
326 foreach (var argument in ca.ConstructorArguments)
327 MarkIfType (argument);
330 void MarkIfType (CustomAttributeArgument argument)
332 var at = argument.Type;
334 var et = at.GetElementType ();
335 if (et.Namespace != "System" || et.Name != "Type")
339 if (argument.Value == null)
342 foreach (var cac in (CustomAttributeArgument[]) argument.Value)
343 MarkWithResolvedScope ((TypeReference) cac.Value);
344 } else if (at.Namespace == "System" && at.Name == "Type") {
345 MarkType (argument.Type);
346 MarkWithResolvedScope ((TypeReference) argument.Value);
350 // custom attributes encoding means it's possible to have a scope that will point into a PCL facade
351 // even if we (just before saving) will resolve all type references (bug #26752)
352 void MarkWithResolvedScope (TypeReference type)
357 // a GenericInstanceType can could contains generic arguments with scope that
358 // needs to be updated out of the PCL facade (bug #28823)
359 var git = (type as GenericInstanceType);
360 if ((git != null) && git.HasGenericArguments) {
361 foreach (var ga in git.GenericArguments)
362 MarkWithResolvedScope (ga);
364 // we cannot set the Scope of a TypeSpecification but it's element type can be set
365 // e.g. System.String[] -> System.String
366 var ts = (type as TypeSpecification);
368 MarkWithResolvedScope (ts.GetElementType ());
372 var td = type.Resolve ();
374 type.Scope = td.Scope;
378 protected bool CheckProcessed (IMetadataTokenProvider provider)
380 if (Annotations.IsProcessed (provider))
383 Annotations.Processed (provider);
387 protected void MarkAssembly (AssemblyDefinition assembly)
389 if (CheckProcessed (assembly))
392 ProcessModule (assembly);
394 MarkCustomAttributes (assembly);
395 MarkSecurityDeclarations (assembly);
397 foreach (ModuleDefinition module in assembly.Modules)
398 MarkCustomAttributes (module);
401 void ProcessModule (AssemblyDefinition assembly)
403 // Pre-mark <Module> if there is any methods as they need to be executed
404 // at assembly load time
405 foreach (TypeDefinition type in assembly.MainModule.Types)
407 if (type.Name == "<Module>" && type.HasMethods)
415 protected void MarkField (FieldReference reference)
417 // if (IgnoreScope (reference.DeclaringType.Scope))
420 if (reference.DeclaringType is GenericInstanceType)
421 MarkType (reference.DeclaringType);
423 FieldDefinition field = ResolveFieldDefinition (reference);
426 throw new ResolutionException (reference);
428 if (CheckProcessed (field))
431 MarkType (field.DeclaringType);
432 MarkType (field.FieldType);
433 MarkCustomAttributes (field);
434 MarkMarshalSpec (field);
436 Annotations.Mark (field);
439 protected virtual bool IgnoreScope (IMetadataScope scope)
441 AssemblyDefinition assembly = ResolveAssembly (scope);
442 return Annotations.GetAction (assembly) != AssemblyAction.Link;
445 FieldDefinition ResolveFieldDefinition (FieldReference field)
447 FieldDefinition fd = field as FieldDefinition;
449 fd = field.Resolve ();
454 void MarkScope (IMetadataScope scope)
456 var provider = scope as IMetadataTokenProvider;
457 if (provider == null)
460 Annotations.Mark (provider);
463 protected virtual void MarkSerializable (TypeDefinition type)
465 MarkDefaultConstructor (type);
466 MarkMethodsIf (type.Methods, IsSpecialSerializationConstructorPredicate);
469 protected virtual TypeDefinition MarkType (TypeReference reference)
471 if (reference == null)
474 reference = GetOriginalType (reference);
476 if (reference is GenericParameter)
479 // if (IgnoreScope (reference.Scope))
482 TypeDefinition type = ResolveTypeDefinition (reference);
485 throw new ResolutionException (reference);
487 if (CheckProcessed (type))
490 Annotations.Push (type);
492 MarkScope (type.Scope);
493 MarkType (type.BaseType);
494 MarkType (type.DeclaringType);
495 MarkCustomAttributes (type);
496 MarkSecurityDeclarations (type);
498 if (IsMulticastDelegate (type)) {
499 MarkMethodCollection (type.Methods);
502 if (IsSerializable (type))
503 MarkSerializable (type);
505 MarkTypeSpecialCustomAttributes (type);
507 MarkGenericParameterProvider (type);
509 // keep fields for value-types and for classes with LayoutKind.Sequential or Explicit
510 if (type.IsValueType || !type.IsAutoLayout)
511 MarkFields (type, type.IsEnum);
513 if (type.HasInterfaces) {
514 foreach (TypeReference iface in type.Interfaces)
518 if (type.HasMethods) {
519 MarkMethodsIf (type.Methods, IsVirtualAndHasPreservedParent);
520 MarkMethodsIf (type.Methods, IsStaticConstructorPredicate);
523 DoAdditionalTypeProcessing (type);
527 Annotations.Mark (type);
529 ApplyPreserveInfo (type);
534 // Allow subclassers to mark additional things when marking a method
535 protected virtual void DoAdditionalTypeProcessing (TypeDefinition method)
539 void MarkTypeSpecialCustomAttributes (TypeDefinition type)
541 if (!type.HasCustomAttributes)
544 foreach (CustomAttribute attribute in type.CustomAttributes) {
545 switch (attribute.Constructor.DeclaringType.FullName) {
546 case "System.Xml.Serialization.XmlSchemaProviderAttribute":
547 MarkXmlSchemaProvider (type, attribute);
553 void MarkMethodSpecialCustomAttributes (MethodDefinition method)
555 if (!method.HasCustomAttributes)
558 foreach (CustomAttribute attribute in method.CustomAttributes) {
559 switch (attribute.Constructor.DeclaringType.FullName) {
560 case "System.Web.Services.Protocols.SoapHeaderAttribute":
561 MarkSoapHeader (method, attribute);
567 void MarkXmlSchemaProvider (TypeDefinition type, CustomAttribute attribute)
570 if (!TryGetStringArgument (attribute, out method_name))
573 MarkNamedMethod (type, method_name);
576 static bool TryGetStringArgument (CustomAttribute attribute, out string argument)
580 if (attribute.ConstructorArguments.Count < 1)
583 argument = attribute.ConstructorArguments [0].Value as string;
585 return argument != null;
588 protected int MarkNamedMethod (TypeDefinition type, string method_name)
590 if (!type.HasMethods)
594 foreach (MethodDefinition method in type.Methods) {
595 if (method.Name != method_name)
605 void MarkSoapHeader (MethodDefinition method, CustomAttribute attribute)
608 if (!TryGetStringArgument (attribute, out member_name))
611 MarkNamedField (method.DeclaringType, member_name);
612 MarkNamedProperty (method.DeclaringType, member_name);
615 void MarkNamedField (TypeDefinition type, string field_name)
620 foreach (FieldDefinition field in type.Fields) {
621 if (field.Name != field_name)
628 void MarkNamedProperty (TypeDefinition type, string property_name)
630 if (!type.HasProperties)
633 foreach (PropertyDefinition property in type.Properties) {
634 if (property.Name != property_name)
637 MarkMethod (property.GetMethod);
638 MarkMethod (property.SetMethod);
642 void MarkGenericParameterProvider (IGenericParameterProvider provider)
644 if (!provider.HasGenericParameters)
647 foreach (GenericParameter parameter in provider.GenericParameters)
648 MarkGenericParameter (parameter);
651 void MarkGenericParameter (GenericParameter parameter)
653 MarkCustomAttributes (parameter);
654 foreach (TypeReference constraint in parameter.Constraints)
655 MarkType (constraint);
658 bool IsVirtualAndHasPreservedParent (MethodDefinition method)
660 if (!method.IsVirtual)
663 var base_list = Annotations.GetBaseMethods (method);
664 if (base_list == null)
667 foreach (MethodDefinition @base in base_list) {
668 if (IgnoreScope (@base.DeclaringType.Scope))
671 if (IsVirtualAndHasPreservedParent (@base))
678 static MethodPredicate IsSpecialSerializationConstructorPredicate = new MethodPredicate (IsSpecialSerializationConstructor);
680 static bool IsSpecialSerializationConstructor (MethodDefinition method)
682 if (!IsConstructor (method))
685 var parameters = method.Parameters;
686 if (parameters.Count != 2)
689 return parameters [0].ParameterType.Name == "SerializationInfo" &&
690 parameters [1].ParameterType.Name == "StreamingContext";
693 delegate bool MethodPredicate (MethodDefinition method);
695 void MarkMethodsIf (ICollection methods, MethodPredicate predicate)
697 foreach (MethodDefinition method in methods)
698 if (predicate (method))
702 static MethodPredicate IsDefaultConstructorPredicate = new MethodPredicate (IsDefaultConstructor);
704 static bool IsDefaultConstructor (MethodDefinition method)
706 return IsConstructor (method) && !method.HasParameters;
709 static bool IsConstructor (MethodDefinition method)
711 return method.IsConstructor && !method.IsStatic;
714 protected void MarkDefaultConstructor (TypeDefinition type)
716 if ((type == null) || !type.HasMethods)
719 MarkMethodsIf (type.Methods, IsDefaultConstructorPredicate);
722 static MethodPredicate IsStaticConstructorPredicate = new MethodPredicate (IsStaticConstructor);
724 static bool IsStaticConstructor (MethodDefinition method)
726 return method.IsConstructor && method.IsStatic;
729 static bool IsSerializable (TypeDefinition td)
731 return (td.Attributes & TypeAttributes.Serializable) != 0;
734 static bool IsMulticastDelegate (TypeDefinition td)
736 return td.BaseType != null && td.BaseType.FullName == "System.MulticastDelegate";
739 protected TypeDefinition ResolveTypeDefinition (TypeReference type)
741 TypeDefinition td = type as TypeDefinition;
743 td = type.Resolve ();
748 protected TypeReference GetOriginalType (TypeReference type)
750 while (type is TypeSpecification) {
751 GenericInstanceType git = type as GenericInstanceType;
753 MarkGenericArguments (git);
755 var mod = type as IModifierType;
757 MarkModifierType (mod);
759 type = ((TypeSpecification) type).ElementType;
765 void MarkModifierType (IModifierType mod)
767 MarkType (mod.ModifierType);
770 void MarkGenericArguments (IGenericInstance instance)
772 foreach (TypeReference argument in instance.GenericArguments)
775 MarkGenericArgumentConstructors (instance);
778 void MarkGenericArgumentConstructors (IGenericInstance instance)
780 var arguments = instance.GenericArguments;
782 var generic_element = GetGenericProviderFromInstance (instance);
783 if (generic_element == null)
786 var parameters = generic_element.GenericParameters;
788 if (arguments.Count != parameters.Count)
791 for (int i = 0; i < arguments.Count; i++) {
792 var argument = arguments [i];
793 var parameter = parameters [i];
795 if (!parameter.HasDefaultConstructorConstraint)
798 var argument_definition = ResolveTypeDefinition (argument);
799 if (argument_definition == null)
802 MarkMethodsIf (argument_definition.Methods, ctor => !ctor.IsStatic && !ctor.HasParameters);
806 IGenericParameterProvider GetGenericProviderFromInstance (IGenericInstance instance)
808 var method = instance as GenericInstanceMethod;
810 return ResolveMethodDefinition (method.ElementMethod);
812 var type = instance as GenericInstanceType;
814 return ResolveTypeDefinition (type.ElementType);
819 void ApplyPreserveInfo (TypeDefinition type)
821 ApplyPreserveMethods (type);
823 if (!Annotations.IsPreserved (type))
826 switch (Annotations.GetPreserve (type)) {
827 case TypePreserve.All:
828 MarkFields (type, true);
831 case TypePreserve.Fields:
832 MarkFields (type, true);
834 case TypePreserve.Methods:
840 void ApplyPreserveMethods (TypeDefinition type)
842 var list = Annotations.GetPreservedMethods (type);
846 MarkMethodCollection (list);
849 void ApplyPreserveMethods (MethodDefinition method)
851 var list = Annotations.GetPreservedMethods (method);
855 MarkMethodCollection (list);
858 protected void MarkFields (TypeDefinition type, bool includeStatic)
863 foreach (FieldDefinition field in type.Fields) {
864 if (!includeStatic && field.IsStatic)
870 protected virtual void MarkMethods (TypeDefinition type)
873 MarkMethodCollection (type.Methods);
876 void MarkMethodCollection (IEnumerable methods)
878 foreach (MethodDefinition method in methods)
882 protected virtual MethodDefinition MarkMethod (MethodReference reference)
884 reference = GetOriginalMethod (reference);
886 if (reference.DeclaringType is ArrayType)
889 Annotations.Push (reference);
890 if (reference.DeclaringType is GenericInstanceType)
891 MarkType (reference.DeclaringType);
893 // if (IgnoreScope (reference.DeclaringType.Scope))
896 MethodDefinition method = ResolveMethodDefinition (reference);
898 if (method == null) {
900 throw new ResolutionException (reference);
903 if (Annotations.GetAction (method) == MethodAction.Nothing)
904 Annotations.SetAction (method, MethodAction.Parse);
906 EnqueueMethod (method);
913 AssemblyDefinition ResolveAssembly (IMetadataScope scope)
915 AssemblyDefinition assembly = _context.Resolve (scope);
916 MarkAssembly (assembly);
920 protected MethodReference GetOriginalMethod (MethodReference method)
922 while (method is MethodSpecification) {
923 GenericInstanceMethod gim = method as GenericInstanceMethod;
925 MarkGenericArguments (gim);
927 method = ((MethodSpecification) method).ElementMethod;
933 MethodDefinition ResolveMethodDefinition (MethodReference method)
935 MethodDefinition md = method as MethodDefinition;
937 md = method.Resolve ();
942 protected virtual void ProcessMethod (MethodDefinition method)
944 if (CheckProcessed (method))
947 MarkType (method.DeclaringType);
948 MarkCustomAttributes (method);
949 MarkSecurityDeclarations (method);
951 MarkGenericParameterProvider (method);
953 if (IsPropertyMethod (method))
954 MarkProperty (GetProperty (method));
955 else if (IsEventMethod (method))
956 MarkEvent (GetEvent (method));
958 if (method.HasParameters) {
959 foreach (ParameterDefinition pd in method.Parameters) {
960 MarkType (pd.ParameterType);
961 MarkCustomAttributes (pd);
962 MarkMarshalSpec (pd);
966 if (method.HasOverrides) {
967 foreach (MethodReference ov in method.Overrides)
971 MarkMethodSpecialCustomAttributes (method);
973 if (method.IsVirtual)
974 _virtual_methods.Add (method);
976 MarkBaseMethods (method);
978 MarkType (method.ReturnType);
979 MarkCustomAttributes (method.MethodReturnType);
980 MarkMarshalSpec (method.MethodReturnType);
982 if (ShouldParseMethodBody (method))
983 MarkMethodBody (method.Body);
985 DoAdditionalMethodProcessing (method);
987 Annotations.Mark (method);
989 ApplyPreserveMethods (method);
992 // Allow subclassers to mark additional things when marking a method
993 protected virtual void DoAdditionalMethodProcessing (MethodDefinition method)
997 void MarkBaseMethods (MethodDefinition method)
999 IList base_methods = Annotations.GetBaseMethods (method);
1000 if (base_methods == null)
1003 foreach (MethodDefinition base_method in base_methods) {
1004 if (base_method.DeclaringType.IsInterface && !method.DeclaringType.IsInterface)
1007 MarkMethod (base_method);
1008 MarkBaseMethods (base_method);
1012 bool ShouldParseMethodBody (MethodDefinition method)
1014 if (!method.HasBody)
1017 AssemblyDefinition assembly = ResolveAssembly (method.DeclaringType.Scope);
1018 return (Annotations.GetAction (method) == MethodAction.ForceParse ||
1019 (Annotations.GetAction (assembly) == AssemblyAction.Link && Annotations.GetAction (method) == MethodAction.Parse));
1022 static internal bool IsPropertyMethod (MethodDefinition md)
1024 return (md.SemanticsAttributes & MethodSemanticsAttributes.Getter) != 0 ||
1025 (md.SemanticsAttributes & MethodSemanticsAttributes.Setter) != 0;
1028 static bool IsEventMethod (MethodDefinition md)
1030 return (md.SemanticsAttributes & MethodSemanticsAttributes.AddOn) != 0 ||
1031 (md.SemanticsAttributes & MethodSemanticsAttributes.Fire) != 0 ||
1032 (md.SemanticsAttributes & MethodSemanticsAttributes.RemoveOn) != 0;
1035 static internal PropertyDefinition GetProperty (MethodDefinition md)
1037 TypeDefinition declaringType = (TypeDefinition) md.DeclaringType;
1038 foreach (PropertyDefinition prop in declaringType.Properties)
1039 if (prop.GetMethod == md || prop.SetMethod == md)
1045 static EventDefinition GetEvent (MethodDefinition md)
1047 TypeDefinition declaringType = (TypeDefinition) md.DeclaringType;
1048 foreach (EventDefinition evt in declaringType.Events)
1049 if (evt.AddMethod == md || evt.InvokeMethod == md || evt.RemoveMethod == md)
1055 protected void MarkProperty (PropertyDefinition prop)
1057 MarkCustomAttributes (prop);
1060 protected void MarkEvent (EventDefinition evt)
1062 MarkCustomAttributes (evt);
1063 MarkMethodIfNotNull (evt.AddMethod);
1064 MarkMethodIfNotNull (evt.InvokeMethod);
1065 MarkMethodIfNotNull (evt.RemoveMethod);
1068 void MarkMethodIfNotNull (MethodReference method)
1073 MarkMethod (method);
1076 protected virtual void MarkMethodBody (MethodBody body)
1078 foreach (VariableDefinition var in body.Variables)
1079 MarkType (var.VariableType);
1081 foreach (ExceptionHandler eh in body.ExceptionHandlers)
1082 if (eh.HandlerType == ExceptionHandlerType.Catch)
1083 MarkType (eh.CatchType);
1085 foreach (Instruction instruction in body.Instructions)
1086 MarkInstruction (instruction);
1089 protected virtual void MarkInstruction (Instruction instruction)
1091 switch (instruction.OpCode.OperandType) {
1092 case OperandType.InlineField:
1093 MarkField ((FieldReference) instruction.Operand);
1095 case OperandType.InlineMethod:
1096 MarkMethod ((MethodReference) instruction.Operand);
1098 case OperandType.InlineTok:
1099 object token = instruction.Operand;
1100 if (token is TypeReference)
1101 MarkType ((TypeReference) token);
1102 else if (token is MethodReference)
1103 MarkMethod ((MethodReference) token);
1105 MarkField ((FieldReference) token);
1107 case OperandType.InlineType:
1108 MarkType ((TypeReference) instruction.Operand);