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 ProcessMethod (method);
132 return _methods.Count == 0;
135 protected virtual void EnqueueMethod (MethodDefinition method)
137 _methods.Enqueue (method);
140 void ProcessVirtualMethods ()
142 foreach (MethodDefinition method in _virtual_methods)
143 ProcessVirtualMethod (method);
146 void ProcessVirtualMethod (MethodDefinition method)
148 IList overrides = Annotations.GetOverrides (method);
149 if (overrides == null)
152 foreach (MethodDefinition @override in overrides)
153 ProcessOverride (@override);
156 void ProcessOverride (MethodDefinition method)
158 if (!Annotations.IsMarked (method.DeclaringType))
161 if (Annotations.IsProcessed (method))
164 if (Annotations.IsMarked (method))
168 ProcessVirtualMethod (method);
171 void MarkMarshalSpec (IMarshalInfoProvider spec)
173 if (!spec.HasMarshalInfo)
176 var marshaler = spec.MarshalInfo as CustomMarshalInfo;
177 if (marshaler == null)
180 MarkType (marshaler.ManagedType);
183 void MarkCustomAttributes (ICustomAttributeProvider provider)
185 if (!provider.HasCustomAttributes)
188 foreach (CustomAttribute ca in provider.CustomAttributes)
189 MarkCustomAttribute (ca);
192 protected virtual void MarkCustomAttribute (CustomAttribute ca)
194 MarkMethod (ca.Constructor);
196 MarkCustomAttributeArguments (ca);
198 TypeReference constructor_type = ca.Constructor.DeclaringType;
199 TypeDefinition type = constructor_type.Resolve ();
201 throw new ResolutionException (constructor_type);
203 MarkCustomAttributeProperties (ca, type);
204 MarkCustomAttributeFields (ca, type);
207 protected void MarkSecurityDeclarations (ISecurityDeclarationProvider provider)
209 // most security declarations are removed (if linked) but user code might still have some
210 // and if the attribtues references types then they need to be marked too
211 if ((provider == null) || !provider.HasSecurityDeclarations)
214 foreach (var sd in provider.SecurityDeclarations)
215 MarkSecurityDeclaration (sd);
218 protected virtual void MarkSecurityDeclaration (SecurityDeclaration sd)
220 if (!sd.HasSecurityAttributes)
223 foreach (var sa in sd.SecurityAttributes)
224 MarkSecurityAttribute (sa);
227 protected virtual void MarkSecurityAttribute (SecurityAttribute sa)
229 TypeReference security_type = sa.AttributeType;
230 TypeDefinition type = security_type.Resolve ();
232 throw new ResolutionException (security_type);
234 MarkType (security_type);
235 MarkSecurityAttributeProperties (sa, type);
236 MarkSecurityAttributeFields (sa, type);
239 protected void MarkSecurityAttributeProperties (SecurityAttribute sa, TypeDefinition attribute)
241 if (!sa.HasProperties)
244 foreach (var named_argument in sa.Properties)
245 MarkCustomAttributeProperty (named_argument, attribute);
248 protected void MarkSecurityAttributeFields (SecurityAttribute sa, TypeDefinition attribute)
253 foreach (var named_argument in sa.Fields)
254 MarkCustomAttributeField (named_argument, attribute);
257 protected void MarkCustomAttributeProperties (CustomAttribute ca, TypeDefinition attribute)
259 if (!ca.HasProperties)
262 foreach (var named_argument in ca.Properties)
263 MarkCustomAttributeProperty (named_argument, attribute);
266 protected void MarkCustomAttributeProperty (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
268 PropertyDefinition property = GetProperty (attribute, namedArgument.Name);
269 if (property != null)
270 MarkMethod (property.SetMethod);
272 MarkIfType (namedArgument.Argument);
275 PropertyDefinition GetProperty (TypeDefinition type, string propertyname)
277 while (type != null) {
278 PropertyDefinition property = type.Properties.FirstOrDefault (p => p.Name == propertyname);
279 if (property != null)
282 type = type.BaseType != null ? ResolveTypeDefinition (type.BaseType) : null;
288 protected void MarkCustomAttributeFields (CustomAttribute ca, TypeDefinition attribute)
293 foreach (var named_argument in ca.Fields)
294 MarkCustomAttributeField (named_argument, attribute);
297 protected void MarkCustomAttributeField (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
299 FieldDefinition field = GetField (attribute, namedArgument.Name);
303 MarkIfType (namedArgument.Argument);
306 FieldDefinition GetField (TypeDefinition type, string fieldname)
308 while (type != null) {
309 FieldDefinition field = type.Fields.FirstOrDefault (f => f.Name == fieldname);
313 type = type.BaseType != null ? ResolveTypeDefinition (type.BaseType) : null;
319 void MarkCustomAttributeArguments (CustomAttribute ca)
321 if (!ca.HasConstructorArguments)
324 foreach (var argument in ca.ConstructorArguments)
325 MarkIfType (argument);
328 void MarkIfType (CustomAttributeArgument argument)
330 var at = argument.Type;
332 var et = at.GetElementType ();
333 if (et.Namespace != "System" || et.Name != "Type")
337 foreach (var cac in (CustomAttributeArgument[]) argument.Value)
338 MarkWithResolvedScope ((TypeReference) cac.Value);
339 } else if (at.Namespace == "System" && at.Name == "Type") {
340 MarkType (argument.Type);
341 MarkWithResolvedScope ((TypeReference) argument.Value);
345 // custom attributes encoding means it's possible to have a scope that will point into a PCL facade
346 // even if we (just before saving) will resolve all type references (bug #26752)
347 void MarkWithResolvedScope (TypeReference type)
352 // a GenericInstanceType can could contains generic arguments with scope that
353 // needs to be updated out of the PCL facade (bug #28823)
354 var git = (type as GenericInstanceType);
355 if ((git != null) && git.HasGenericArguments) {
356 foreach (var ga in git.GenericArguments)
357 MarkWithResolvedScope (ga);
360 // we cannot set the Scope of a TypeSpecification but it's element type can be set
361 // e.g. System.String[] -> System.String
362 var ts = (type as TypeSpecification);
364 MarkWithResolvedScope (ts.GetElementType ());
368 var td = type.Resolve ();
370 type.Scope = td.Scope;
374 protected bool CheckProcessed (IMetadataTokenProvider provider)
376 if (Annotations.IsProcessed (provider))
379 Annotations.Processed (provider);
383 protected void MarkAssembly (AssemblyDefinition assembly)
385 if (CheckProcessed (assembly))
388 ProcessModule (assembly);
390 MarkCustomAttributes (assembly);
391 MarkSecurityDeclarations (assembly);
393 foreach (ModuleDefinition module in assembly.Modules)
394 MarkCustomAttributes (module);
397 void ProcessModule (AssemblyDefinition assembly)
399 // Pre-mark <Module> if there is any methods as they need to be executed
400 // at assembly load time
401 foreach (TypeDefinition type in assembly.MainModule.Types)
403 if (type.Name == "<Module>" && type.HasMethods)
411 protected void MarkField (FieldReference reference)
413 // if (IgnoreScope (reference.DeclaringType.Scope))
416 if (reference.DeclaringType is GenericInstanceType)
417 MarkType (reference.DeclaringType);
419 FieldDefinition field = ResolveFieldDefinition (reference);
422 throw new ResolutionException (reference);
424 if (CheckProcessed (field))
427 MarkType (field.DeclaringType);
428 MarkType (field.FieldType);
429 MarkCustomAttributes (field);
430 MarkMarshalSpec (field);
432 Annotations.Mark (field);
435 protected virtual bool IgnoreScope (IMetadataScope scope)
437 AssemblyDefinition assembly = ResolveAssembly (scope);
438 return Annotations.GetAction (assembly) != AssemblyAction.Link;
441 FieldDefinition ResolveFieldDefinition (FieldReference field)
443 FieldDefinition fd = field as FieldDefinition;
445 fd = field.Resolve ();
450 void MarkScope (IMetadataScope scope)
452 var provider = scope as IMetadataTokenProvider;
453 if (provider == null)
456 Annotations.Mark (provider);
459 protected virtual void MarkSerializable (TypeDefinition type)
461 MarkDefaultConstructor (type);
462 MarkMethodsIf (type.Methods, IsSpecialSerializationConstructorPredicate);
465 protected virtual TypeDefinition MarkType (TypeReference reference)
467 if (reference == null)
470 reference = GetOriginalType (reference);
472 if (reference is GenericParameter)
475 // if (IgnoreScope (reference.Scope))
478 TypeDefinition type = ResolveTypeDefinition (reference);
481 throw new ResolutionException (reference);
483 if (CheckProcessed (type))
486 MarkScope (type.Scope);
487 MarkType (type.BaseType);
488 MarkType (type.DeclaringType);
489 MarkCustomAttributes (type);
490 MarkSecurityDeclarations (type);
492 if (IsMulticastDelegate (type)) {
493 MarkMethodCollection (type.Methods);
496 if (IsSerializable (type))
497 MarkSerializable (type);
499 MarkTypeSpecialCustomAttributes (type);
501 MarkGenericParameterProvider (type);
503 // keep fields for value-types and for classes with LayoutKind.Sequential or Explicit
504 if (type.IsValueType || !type.IsAutoLayout)
505 MarkFields (type, type.IsEnum);
507 if (type.HasInterfaces) {
508 foreach (TypeReference iface in type.Interfaces)
512 if (type.HasMethods) {
513 MarkMethodsIf (type.Methods, IsVirtualAndHasPreservedParent);
514 MarkMethodsIf (type.Methods, IsStaticConstructorPredicate);
517 DoAdditionalTypeProcessing (type);
519 Annotations.Mark (type);
521 ApplyPreserveInfo (type);
526 // Allow subclassers to mark additional things when marking a method
527 protected virtual void DoAdditionalTypeProcessing (TypeDefinition method)
531 void MarkTypeSpecialCustomAttributes (TypeDefinition type)
533 if (!type.HasCustomAttributes)
536 foreach (CustomAttribute attribute in type.CustomAttributes) {
537 switch (attribute.Constructor.DeclaringType.FullName) {
538 case "System.Xml.Serialization.XmlSchemaProviderAttribute":
539 MarkXmlSchemaProvider (type, attribute);
545 void MarkMethodSpecialCustomAttributes (MethodDefinition method)
547 if (!method.HasCustomAttributes)
550 foreach (CustomAttribute attribute in method.CustomAttributes) {
551 switch (attribute.Constructor.DeclaringType.FullName) {
552 case "System.Web.Services.Protocols.SoapHeaderAttribute":
553 MarkSoapHeader (method, attribute);
559 void MarkXmlSchemaProvider (TypeDefinition type, CustomAttribute attribute)
562 if (!TryGetStringArgument (attribute, out method_name))
565 MarkNamedMethod (type, method_name);
568 static bool TryGetStringArgument (CustomAttribute attribute, out string argument)
572 if (attribute.ConstructorArguments.Count < 1)
575 argument = attribute.ConstructorArguments [0].Value as string;
577 return argument != null;
580 protected int MarkNamedMethod (TypeDefinition type, string method_name)
582 if (!type.HasMethods)
586 foreach (MethodDefinition method in type.Methods) {
587 if (method.Name != method_name)
597 void MarkSoapHeader (MethodDefinition method, CustomAttribute attribute)
600 if (!TryGetStringArgument (attribute, out member_name))
603 MarkNamedField (method.DeclaringType, member_name);
604 MarkNamedProperty (method.DeclaringType, member_name);
607 void MarkNamedField (TypeDefinition type, string field_name)
612 foreach (FieldDefinition field in type.Fields) {
613 if (field.Name != field_name)
620 void MarkNamedProperty (TypeDefinition type, string property_name)
622 if (!type.HasProperties)
625 foreach (PropertyDefinition property in type.Properties) {
626 if (property.Name != property_name)
629 MarkMethod (property.GetMethod);
630 MarkMethod (property.SetMethod);
634 void MarkGenericParameterProvider (IGenericParameterProvider provider)
636 if (!provider.HasGenericParameters)
639 foreach (GenericParameter parameter in provider.GenericParameters)
640 MarkGenericParameter (parameter);
643 void MarkGenericParameter (GenericParameter parameter)
645 MarkCustomAttributes (parameter);
646 foreach (TypeReference constraint in parameter.Constraints)
647 MarkType (constraint);
650 bool IsVirtualAndHasPreservedParent (MethodDefinition method)
652 if (!method.IsVirtual)
655 var base_list = Annotations.GetBaseMethods (method);
656 if (base_list == null)
659 foreach (MethodDefinition @base in base_list) {
660 if (IgnoreScope (@base.DeclaringType.Scope))
663 if (IsVirtualAndHasPreservedParent (@base))
670 static MethodPredicate IsSpecialSerializationConstructorPredicate = new MethodPredicate (IsSpecialSerializationConstructor);
672 static bool IsSpecialSerializationConstructor (MethodDefinition method)
674 if (!IsConstructor (method))
677 var parameters = method.Parameters;
678 if (parameters.Count != 2)
681 return parameters [0].ParameterType.Name == "SerializationInfo" &&
682 parameters [1].ParameterType.Name == "StreamingContext";
685 delegate bool MethodPredicate (MethodDefinition method);
687 void MarkMethodsIf (ICollection methods, MethodPredicate predicate)
689 foreach (MethodDefinition method in methods)
690 if (predicate (method))
694 static MethodPredicate IsDefaultConstructorPredicate = new MethodPredicate (IsDefaultConstructor);
696 static bool IsDefaultConstructor (MethodDefinition method)
698 return IsConstructor (method) && !method.HasParameters;
701 static bool IsConstructor (MethodDefinition method)
703 return method.IsConstructor && !method.IsStatic;
706 protected void MarkDefaultConstructor (TypeDefinition type)
708 if ((type == null) || !type.HasMethods)
711 MarkMethodsIf (type.Methods, IsDefaultConstructorPredicate);
714 static MethodPredicate IsStaticConstructorPredicate = new MethodPredicate (IsStaticConstructor);
716 static bool IsStaticConstructor (MethodDefinition method)
718 return method.IsConstructor && method.IsStatic;
721 static bool IsSerializable (TypeDefinition td)
723 return (td.Attributes & TypeAttributes.Serializable) != 0;
726 static bool IsMulticastDelegate (TypeDefinition td)
728 return td.BaseType != null && td.BaseType.FullName == "System.MulticastDelegate";
731 protected TypeDefinition ResolveTypeDefinition (TypeReference type)
733 TypeDefinition td = type as TypeDefinition;
735 td = type.Resolve ();
740 protected TypeReference GetOriginalType (TypeReference type)
742 while (type is TypeSpecification) {
743 GenericInstanceType git = type as GenericInstanceType;
745 MarkGenericArguments (git);
747 var mod = type as IModifierType;
749 MarkModifierType (mod);
751 type = ((TypeSpecification) type).ElementType;
757 void MarkModifierType (IModifierType mod)
759 MarkType (mod.ModifierType);
762 void MarkGenericArguments (IGenericInstance instance)
764 foreach (TypeReference argument in instance.GenericArguments)
767 MarkGenericArgumentConstructors (instance);
770 void MarkGenericArgumentConstructors (IGenericInstance instance)
772 var arguments = instance.GenericArguments;
774 var generic_element = GetGenericProviderFromInstance (instance);
775 if (generic_element == null)
778 var parameters = generic_element.GenericParameters;
780 if (arguments.Count != parameters.Count)
783 for (int i = 0; i < arguments.Count; i++) {
784 var argument = arguments [i];
785 var parameter = parameters [i];
787 if (!parameter.HasDefaultConstructorConstraint)
790 var argument_definition = ResolveTypeDefinition (argument);
791 if (argument_definition == null)
794 MarkMethodsIf (argument_definition.Methods, ctor => !ctor.IsStatic && !ctor.HasParameters);
798 IGenericParameterProvider GetGenericProviderFromInstance (IGenericInstance instance)
800 var method = instance as GenericInstanceMethod;
802 return ResolveMethodDefinition (method.ElementMethod);
804 var type = instance as GenericInstanceType;
806 return ResolveTypeDefinition (type.ElementType);
811 void ApplyPreserveInfo (TypeDefinition type)
813 ApplyPreserveMethods (type);
815 if (!Annotations.IsPreserved (type))
818 switch (Annotations.GetPreserve (type)) {
819 case TypePreserve.All:
820 MarkFields (type, true);
823 case TypePreserve.Fields:
824 MarkFields (type, true);
826 case TypePreserve.Methods:
832 void ApplyPreserveMethods (TypeDefinition type)
834 var list = Annotations.GetPreservedMethods (type);
838 MarkMethodCollection (list);
841 void ApplyPreserveMethods (MethodDefinition method)
843 var list = Annotations.GetPreservedMethods (method);
847 MarkMethodCollection (list);
850 protected void MarkFields (TypeDefinition type, bool includeStatic)
855 foreach (FieldDefinition field in type.Fields) {
856 if (!includeStatic && field.IsStatic)
862 protected virtual void MarkMethods (TypeDefinition type)
865 MarkMethodCollection (type.Methods);
868 void MarkMethodCollection (IEnumerable methods)
870 foreach (MethodDefinition method in methods)
874 protected virtual MethodDefinition MarkMethod (MethodReference reference)
876 reference = GetOriginalMethod (reference);
878 if (reference.DeclaringType is ArrayType)
881 if (reference.DeclaringType is GenericInstanceType)
882 MarkType (reference.DeclaringType);
884 // if (IgnoreScope (reference.DeclaringType.Scope))
887 MethodDefinition method = ResolveMethodDefinition (reference);
890 throw new ResolutionException (reference);
892 if (Annotations.GetAction (method) == MethodAction.Nothing)
893 Annotations.SetAction (method, MethodAction.Parse);
895 EnqueueMethod (method);
899 AssemblyDefinition ResolveAssembly (IMetadataScope scope)
901 AssemblyDefinition assembly = _context.Resolve (scope);
902 MarkAssembly (assembly);
906 protected MethodReference GetOriginalMethod (MethodReference method)
908 while (method is MethodSpecification) {
909 GenericInstanceMethod gim = method as GenericInstanceMethod;
911 MarkGenericArguments (gim);
913 method = ((MethodSpecification) method).ElementMethod;
919 MethodDefinition ResolveMethodDefinition (MethodReference method)
921 MethodDefinition md = method as MethodDefinition;
923 md = method.Resolve ();
928 protected virtual void ProcessMethod (MethodDefinition method)
930 if (CheckProcessed (method))
933 MarkType (method.DeclaringType);
934 MarkCustomAttributes (method);
935 MarkSecurityDeclarations (method);
937 MarkGenericParameterProvider (method);
939 if (IsPropertyMethod (method))
940 MarkProperty (GetProperty (method));
941 else if (IsEventMethod (method))
942 MarkEvent (GetEvent (method));
944 if (method.HasParameters) {
945 foreach (ParameterDefinition pd in method.Parameters) {
946 MarkType (pd.ParameterType);
947 MarkCustomAttributes (pd);
948 MarkMarshalSpec (pd);
952 if (method.HasOverrides) {
953 foreach (MethodReference ov in method.Overrides)
957 MarkMethodSpecialCustomAttributes (method);
959 if (method.IsVirtual)
960 _virtual_methods.Add (method);
962 MarkBaseMethods (method);
964 MarkType (method.ReturnType);
965 MarkCustomAttributes (method.MethodReturnType);
966 MarkMarshalSpec (method.MethodReturnType);
968 if (ShouldParseMethodBody (method))
969 MarkMethodBody (method.Body);
971 DoAdditionalMethodProcessing (method);
973 Annotations.Mark (method);
975 ApplyPreserveMethods (method);
978 // Allow subclassers to mark additional things when marking a method
979 protected virtual void DoAdditionalMethodProcessing (MethodDefinition method)
983 void MarkBaseMethods (MethodDefinition method)
985 IList base_methods = Annotations.GetBaseMethods (method);
986 if (base_methods == null)
989 foreach (MethodDefinition base_method in base_methods) {
990 if (base_method.DeclaringType.IsInterface && !method.DeclaringType.IsInterface)
993 MarkMethod (base_method);
994 MarkBaseMethods (base_method);
998 bool ShouldParseMethodBody (MethodDefinition method)
1000 if (!method.HasBody)
1003 AssemblyDefinition assembly = ResolveAssembly (method.DeclaringType.Scope);
1004 return (Annotations.GetAction (method) == MethodAction.ForceParse ||
1005 (Annotations.GetAction (assembly) == AssemblyAction.Link && Annotations.GetAction (method) == MethodAction.Parse));
1008 static internal bool IsPropertyMethod (MethodDefinition md)
1010 return (md.SemanticsAttributes & MethodSemanticsAttributes.Getter) != 0 ||
1011 (md.SemanticsAttributes & MethodSemanticsAttributes.Setter) != 0;
1014 static bool IsEventMethod (MethodDefinition md)
1016 return (md.SemanticsAttributes & MethodSemanticsAttributes.AddOn) != 0 ||
1017 (md.SemanticsAttributes & MethodSemanticsAttributes.Fire) != 0 ||
1018 (md.SemanticsAttributes & MethodSemanticsAttributes.RemoveOn) != 0;
1021 static internal PropertyDefinition GetProperty (MethodDefinition md)
1023 TypeDefinition declaringType = (TypeDefinition) md.DeclaringType;
1024 foreach (PropertyDefinition prop in declaringType.Properties)
1025 if (prop.GetMethod == md || prop.SetMethod == md)
1031 static EventDefinition GetEvent (MethodDefinition md)
1033 TypeDefinition declaringType = (TypeDefinition) md.DeclaringType;
1034 foreach (EventDefinition evt in declaringType.Events)
1035 if (evt.AddMethod == md || evt.InvokeMethod == md || evt.RemoveMethod == md)
1041 protected void MarkProperty (PropertyDefinition prop)
1043 MarkCustomAttributes (prop);
1046 protected void MarkEvent (EventDefinition evt)
1048 MarkCustomAttributes (evt);
1049 MarkMethodIfNotNull (evt.AddMethod);
1050 MarkMethodIfNotNull (evt.InvokeMethod);
1051 MarkMethodIfNotNull (evt.RemoveMethod);
1054 void MarkMethodIfNotNull (MethodReference method)
1059 MarkMethod (method);
1062 protected virtual void MarkMethodBody (MethodBody body)
1064 foreach (VariableDefinition var in body.Variables)
1065 MarkType (var.VariableType);
1067 foreach (ExceptionHandler eh in body.ExceptionHandlers)
1068 if (eh.HandlerType == ExceptionHandlerType.Catch)
1069 MarkType (eh.CatchType);
1071 foreach (Instruction instruction in body.Instructions)
1072 MarkInstruction (instruction);
1075 protected virtual void MarkInstruction (Instruction instruction)
1077 switch (instruction.OpCode.OperandType) {
1078 case OperandType.InlineField:
1079 MarkField ((FieldReference) instruction.Operand);
1081 case OperandType.InlineMethod:
1082 MarkMethod ((MethodReference) instruction.Operand);
1084 case OperandType.InlineTok:
1085 object token = instruction.Operand;
1086 if (token is TypeReference)
1087 MarkType ((TypeReference) token);
1088 else if (token is MethodReference)
1089 MarkMethod ((MethodReference) token);
1091 MarkField ((FieldReference) token);
1093 case OperandType.InlineType:
1094 MarkType ((TypeReference) instruction.Operand);