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 Annotations.Push (method);
146 ProcessVirtualMethod (method);
151 void ProcessVirtualMethod (MethodDefinition method)
153 IList overrides = Annotations.GetOverrides (method);
154 if (overrides == null)
157 foreach (MethodDefinition @override in overrides)
158 ProcessOverride (@override);
161 void ProcessOverride (MethodDefinition method)
163 if (!Annotations.IsMarked (method.DeclaringType))
166 if (Annotations.IsProcessed (method))
169 if (Annotations.IsMarked (method))
173 ProcessVirtualMethod (method);
176 void MarkMarshalSpec (IMarshalInfoProvider spec)
178 if (!spec.HasMarshalInfo)
181 var marshaler = spec.MarshalInfo as CustomMarshalInfo;
182 if (marshaler == null)
185 MarkType (marshaler.ManagedType);
188 void MarkCustomAttributes (ICustomAttributeProvider provider)
190 if (!provider.HasCustomAttributes)
193 foreach (CustomAttribute ca in provider.CustomAttributes)
194 MarkCustomAttribute (ca);
197 protected virtual void MarkCustomAttribute (CustomAttribute ca)
199 Annotations.Push (ca);
200 MarkMethod (ca.Constructor);
202 MarkCustomAttributeArguments (ca);
204 TypeReference constructor_type = ca.Constructor.DeclaringType;
205 TypeDefinition type = constructor_type.Resolve ();
208 throw new ResolutionException (constructor_type);
211 MarkCustomAttributeProperties (ca, type);
212 MarkCustomAttributeFields (ca, type);
216 protected void MarkSecurityDeclarations (ISecurityDeclarationProvider provider)
218 // most security declarations are removed (if linked) but user code might still have some
219 // and if the attribtues references types then they need to be marked too
220 if ((provider == null) || !provider.HasSecurityDeclarations)
223 foreach (var sd in provider.SecurityDeclarations)
224 MarkSecurityDeclaration (sd);
227 protected virtual void MarkSecurityDeclaration (SecurityDeclaration sd)
229 if (!sd.HasSecurityAttributes)
232 foreach (var sa in sd.SecurityAttributes)
233 MarkSecurityAttribute (sa);
236 protected virtual void MarkSecurityAttribute (SecurityAttribute sa)
238 TypeReference security_type = sa.AttributeType;
239 TypeDefinition type = security_type.Resolve ();
241 throw new ResolutionException (security_type);
243 MarkType (security_type);
244 MarkSecurityAttributeProperties (sa, type);
245 MarkSecurityAttributeFields (sa, type);
248 protected void MarkSecurityAttributeProperties (SecurityAttribute sa, TypeDefinition attribute)
250 if (!sa.HasProperties)
253 foreach (var named_argument in sa.Properties)
254 MarkCustomAttributeProperty (named_argument, attribute);
257 protected void MarkSecurityAttributeFields (SecurityAttribute sa, TypeDefinition attribute)
262 foreach (var named_argument in sa.Fields)
263 MarkCustomAttributeField (named_argument, attribute);
266 protected void MarkCustomAttributeProperties (CustomAttribute ca, TypeDefinition attribute)
268 if (!ca.HasProperties)
271 foreach (var named_argument in ca.Properties)
272 MarkCustomAttributeProperty (named_argument, attribute);
275 protected void MarkCustomAttributeProperty (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
277 PropertyDefinition property = GetProperty (attribute, namedArgument.Name);
278 Annotations.Push (property);
279 if (property != null)
280 MarkMethod (property.SetMethod);
282 MarkIfType (namedArgument.Argument);
286 PropertyDefinition GetProperty (TypeDefinition type, string propertyname)
288 while (type != null) {
289 PropertyDefinition property = type.Properties.FirstOrDefault (p => p.Name == propertyname);
290 if (property != null)
293 type = type.BaseType != null ? ResolveTypeDefinition (type.BaseType) : null;
299 protected void MarkCustomAttributeFields (CustomAttribute ca, TypeDefinition attribute)
304 foreach (var named_argument in ca.Fields)
305 MarkCustomAttributeField (named_argument, attribute);
308 protected void MarkCustomAttributeField (CustomAttributeNamedArgument namedArgument, TypeDefinition attribute)
310 FieldDefinition field = GetField (attribute, namedArgument.Name);
314 MarkIfType (namedArgument.Argument);
317 FieldDefinition GetField (TypeDefinition type, string fieldname)
319 while (type != null) {
320 FieldDefinition field = type.Fields.FirstOrDefault (f => f.Name == fieldname);
324 type = type.BaseType != null ? ResolveTypeDefinition (type.BaseType) : null;
330 void MarkCustomAttributeArguments (CustomAttribute ca)
332 if (!ca.HasConstructorArguments)
335 foreach (var argument in ca.ConstructorArguments)
336 MarkIfType (argument);
339 void MarkIfType (CustomAttributeArgument argument)
341 var at = argument.Type;
343 var et = at.GetElementType ();
344 if (et.Namespace != "System" || et.Name != "Type")
348 if (argument.Value == null)
351 foreach (var cac in (CustomAttributeArgument[]) argument.Value)
352 MarkWithResolvedScope ((TypeReference) cac.Value);
353 } else if (at.Namespace == "System" && at.Name == "Type") {
354 MarkType (argument.Type);
355 MarkWithResolvedScope ((TypeReference) argument.Value);
359 // custom attributes encoding means it's possible to have a scope that will point into a PCL facade
360 // even if we (just before saving) will resolve all type references (bug #26752)
361 void MarkWithResolvedScope (TypeReference type)
366 // a GenericInstanceType can could contains generic arguments with scope that
367 // needs to be updated out of the PCL facade (bug #28823)
368 var git = (type as GenericInstanceType);
369 if ((git != null) && git.HasGenericArguments) {
370 foreach (var ga in git.GenericArguments)
371 MarkWithResolvedScope (ga);
373 // we cannot set the Scope of a TypeSpecification but it's element type can be set
374 // e.g. System.String[] -> System.String
375 var ts = (type as TypeSpecification);
377 MarkWithResolvedScope (ts.GetElementType ());
381 var td = type.Resolve ();
383 type.Scope = td.Scope;
387 protected bool CheckProcessed (IMetadataTokenProvider provider)
389 if (Annotations.IsProcessed (provider))
392 Annotations.Processed (provider);
396 protected void MarkAssembly (AssemblyDefinition assembly)
398 if (CheckProcessed (assembly))
401 ProcessModule (assembly);
403 MarkCustomAttributes (assembly);
404 MarkSecurityDeclarations (assembly);
406 foreach (ModuleDefinition module in assembly.Modules)
407 MarkCustomAttributes (module);
410 void ProcessModule (AssemblyDefinition assembly)
412 // Pre-mark <Module> if there is any methods as they need to be executed
413 // at assembly load time
414 foreach (TypeDefinition type in assembly.MainModule.Types)
416 if (type.Name == "<Module>" && type.HasMethods)
424 protected void MarkField (FieldReference reference)
426 // if (IgnoreScope (reference.DeclaringType.Scope))
429 if (reference.DeclaringType is GenericInstanceType)
430 MarkType (reference.DeclaringType);
432 FieldDefinition field = ResolveFieldDefinition (reference);
435 throw new ResolutionException (reference);
437 if (CheckProcessed (field))
440 MarkType (field.DeclaringType);
441 MarkType (field.FieldType);
442 MarkCustomAttributes (field);
443 MarkMarshalSpec (field);
445 Annotations.Mark (field);
448 protected virtual bool IgnoreScope (IMetadataScope scope)
450 AssemblyDefinition assembly = ResolveAssembly (scope);
451 return Annotations.GetAction (assembly) != AssemblyAction.Link;
454 FieldDefinition ResolveFieldDefinition (FieldReference field)
456 FieldDefinition fd = field as FieldDefinition;
458 fd = field.Resolve ();
463 void MarkScope (IMetadataScope scope)
465 var provider = scope as IMetadataTokenProvider;
466 if (provider == null)
469 Annotations.Mark (provider);
472 protected virtual void MarkSerializable (TypeDefinition type)
474 MarkDefaultConstructor (type);
475 MarkMethodsIf (type.Methods, IsSpecialSerializationConstructorPredicate);
478 protected virtual TypeDefinition MarkType (TypeReference reference)
480 if (reference == null)
483 reference = GetOriginalType (reference);
485 if (reference is GenericParameter)
488 // if (IgnoreScope (reference.Scope))
491 TypeDefinition type = ResolveTypeDefinition (reference);
494 throw new ResolutionException (reference);
496 if (CheckProcessed (type))
499 Annotations.Push (type);
501 MarkScope (type.Scope);
502 MarkType (type.BaseType);
503 MarkType (type.DeclaringType);
504 MarkCustomAttributes (type);
505 MarkSecurityDeclarations (type);
507 if (IsMulticastDelegate (type)) {
508 MarkMethodCollection (type.Methods);
511 if (IsSerializable (type))
512 MarkSerializable (type);
514 MarkTypeSpecialCustomAttributes (type);
516 MarkGenericParameterProvider (type);
518 // keep fields for value-types and for classes with LayoutKind.Sequential or Explicit
519 if (type.IsValueType || !type.IsAutoLayout)
520 MarkFields (type, type.IsEnum);
522 if (type.HasInterfaces) {
523 foreach (TypeReference iface in type.Interfaces)
527 if (type.HasMethods) {
528 MarkMethodsIf (type.Methods, IsVirtualAndHasPreservedParent);
529 MarkMethodsIf (type.Methods, IsStaticConstructorPredicate);
532 DoAdditionalTypeProcessing (type);
536 Annotations.Mark (type);
538 ApplyPreserveInfo (type);
543 // Allow subclassers to mark additional things when marking a method
544 protected virtual void DoAdditionalTypeProcessing (TypeDefinition method)
548 void MarkTypeSpecialCustomAttributes (TypeDefinition type)
550 if (!type.HasCustomAttributes)
553 foreach (CustomAttribute attribute in type.CustomAttributes) {
554 switch (attribute.Constructor.DeclaringType.FullName) {
555 case "System.Xml.Serialization.XmlSchemaProviderAttribute":
556 MarkXmlSchemaProvider (type, attribute);
562 void MarkMethodSpecialCustomAttributes (MethodDefinition method)
564 if (!method.HasCustomAttributes)
567 foreach (CustomAttribute attribute in method.CustomAttributes) {
568 switch (attribute.Constructor.DeclaringType.FullName) {
569 case "System.Web.Services.Protocols.SoapHeaderAttribute":
570 MarkSoapHeader (method, attribute);
576 void MarkXmlSchemaProvider (TypeDefinition type, CustomAttribute attribute)
579 if (!TryGetStringArgument (attribute, out method_name))
582 MarkNamedMethod (type, method_name);
585 static bool TryGetStringArgument (CustomAttribute attribute, out string argument)
589 if (attribute.ConstructorArguments.Count < 1)
592 argument = attribute.ConstructorArguments [0].Value as string;
594 return argument != null;
597 protected int MarkNamedMethod (TypeDefinition type, string method_name)
599 if (!type.HasMethods)
603 foreach (MethodDefinition method in type.Methods) {
604 if (method.Name != method_name)
614 void MarkSoapHeader (MethodDefinition method, CustomAttribute attribute)
617 if (!TryGetStringArgument (attribute, out member_name))
620 MarkNamedField (method.DeclaringType, member_name);
621 MarkNamedProperty (method.DeclaringType, member_name);
624 void MarkNamedField (TypeDefinition type, string field_name)
629 foreach (FieldDefinition field in type.Fields) {
630 if (field.Name != field_name)
637 void MarkNamedProperty (TypeDefinition type, string property_name)
639 if (!type.HasProperties)
642 foreach (PropertyDefinition property in type.Properties) {
643 if (property.Name != property_name)
646 Annotations.Push (property);
647 MarkMethod (property.GetMethod);
648 MarkMethod (property.SetMethod);
653 void MarkGenericParameterProvider (IGenericParameterProvider provider)
655 if (!provider.HasGenericParameters)
658 foreach (GenericParameter parameter in provider.GenericParameters)
659 MarkGenericParameter (parameter);
662 void MarkGenericParameter (GenericParameter parameter)
664 MarkCustomAttributes (parameter);
665 foreach (TypeReference constraint in parameter.Constraints)
666 MarkType (constraint);
669 bool IsVirtualAndHasPreservedParent (MethodDefinition method)
671 if (!method.IsVirtual)
674 var base_list = Annotations.GetBaseMethods (method);
675 if (base_list == null)
678 foreach (MethodDefinition @base in base_list) {
679 if (IgnoreScope (@base.DeclaringType.Scope))
682 if (IsVirtualAndHasPreservedParent (@base))
689 static MethodPredicate IsSpecialSerializationConstructorPredicate = new MethodPredicate (IsSpecialSerializationConstructor);
691 static bool IsSpecialSerializationConstructor (MethodDefinition method)
693 if (!IsConstructor (method))
696 var parameters = method.Parameters;
697 if (parameters.Count != 2)
700 return parameters [0].ParameterType.Name == "SerializationInfo" &&
701 parameters [1].ParameterType.Name == "StreamingContext";
704 delegate bool MethodPredicate (MethodDefinition method);
706 void MarkMethodsIf (ICollection methods, MethodPredicate predicate)
708 foreach (MethodDefinition method in methods)
709 if (predicate (method)) {
710 Annotations.Push (predicate);
716 static MethodPredicate IsDefaultConstructorPredicate = new MethodPredicate (IsDefaultConstructor);
718 static bool IsDefaultConstructor (MethodDefinition method)
720 return IsConstructor (method) && !method.HasParameters;
723 static bool IsConstructor (MethodDefinition method)
725 return method.IsConstructor && !method.IsStatic;
728 protected void MarkDefaultConstructor (TypeDefinition type)
730 if ((type == null) || !type.HasMethods)
733 MarkMethodsIf (type.Methods, IsDefaultConstructorPredicate);
736 static MethodPredicate IsStaticConstructorPredicate = new MethodPredicate (IsStaticConstructor);
738 static bool IsStaticConstructor (MethodDefinition method)
740 return method.IsConstructor && method.IsStatic;
743 static bool IsSerializable (TypeDefinition td)
745 return (td.Attributes & TypeAttributes.Serializable) != 0;
748 static bool IsMulticastDelegate (TypeDefinition td)
750 return td.BaseType != null && td.BaseType.FullName == "System.MulticastDelegate";
753 protected TypeDefinition ResolveTypeDefinition (TypeReference type)
755 TypeDefinition td = type as TypeDefinition;
757 td = type.Resolve ();
762 protected TypeReference GetOriginalType (TypeReference type)
764 while (type is TypeSpecification) {
765 GenericInstanceType git = type as GenericInstanceType;
767 MarkGenericArguments (git);
769 var mod = type as IModifierType;
771 MarkModifierType (mod);
773 type = ((TypeSpecification) type).ElementType;
779 void MarkModifierType (IModifierType mod)
781 MarkType (mod.ModifierType);
784 void MarkGenericArguments (IGenericInstance instance)
786 foreach (TypeReference argument in instance.GenericArguments)
789 MarkGenericArgumentConstructors (instance);
792 void MarkGenericArgumentConstructors (IGenericInstance instance)
794 var arguments = instance.GenericArguments;
796 var generic_element = GetGenericProviderFromInstance (instance);
797 if (generic_element == null)
800 var parameters = generic_element.GenericParameters;
802 if (arguments.Count != parameters.Count)
805 for (int i = 0; i < arguments.Count; i++) {
806 var argument = arguments [i];
807 var parameter = parameters [i];
809 if (!parameter.HasDefaultConstructorConstraint)
812 var argument_definition = ResolveTypeDefinition (argument);
813 if (argument_definition == null)
816 MarkMethodsIf (argument_definition.Methods, ctor => !ctor.IsStatic && !ctor.HasParameters);
820 IGenericParameterProvider GetGenericProviderFromInstance (IGenericInstance instance)
822 var method = instance as GenericInstanceMethod;
824 return ResolveMethodDefinition (method.ElementMethod);
826 var type = instance as GenericInstanceType;
828 return ResolveTypeDefinition (type.ElementType);
833 void ApplyPreserveInfo (TypeDefinition type)
835 ApplyPreserveMethods (type);
837 if (!Annotations.IsPreserved (type))
840 switch (Annotations.GetPreserve (type)) {
841 case TypePreserve.All:
842 MarkFields (type, true);
845 case TypePreserve.Fields:
846 MarkFields (type, true);
848 case TypePreserve.Methods:
854 void ApplyPreserveMethods (TypeDefinition type)
856 var list = Annotations.GetPreservedMethods (type);
860 MarkMethodCollection (list);
863 void ApplyPreserveMethods (MethodDefinition method)
865 var list = Annotations.GetPreservedMethods (method);
869 MarkMethodCollection (list);
872 protected void MarkFields (TypeDefinition type, bool includeStatic)
877 foreach (FieldDefinition field in type.Fields) {
878 if (!includeStatic && field.IsStatic)
884 protected virtual void MarkMethods (TypeDefinition type)
887 MarkMethodCollection (type.Methods);
890 void MarkMethodCollection (IEnumerable methods)
892 foreach (MethodDefinition method in methods)
896 protected virtual MethodDefinition MarkMethod (MethodReference reference)
898 reference = GetOriginalMethod (reference);
900 if (reference.DeclaringType is ArrayType)
903 Annotations.Push (reference);
904 if (reference.DeclaringType is GenericInstanceType)
905 MarkType (reference.DeclaringType);
907 // if (IgnoreScope (reference.DeclaringType.Scope))
910 MethodDefinition method = ResolveMethodDefinition (reference);
912 if (method == null) {
914 throw new ResolutionException (reference);
917 if (Annotations.GetAction (method) == MethodAction.Nothing)
918 Annotations.SetAction (method, MethodAction.Parse);
920 EnqueueMethod (method);
923 Annotations.AddDependency (method);
928 AssemblyDefinition ResolveAssembly (IMetadataScope scope)
930 AssemblyDefinition assembly = _context.Resolve (scope);
931 MarkAssembly (assembly);
935 protected MethodReference GetOriginalMethod (MethodReference method)
937 while (method is MethodSpecification) {
938 GenericInstanceMethod gim = method as GenericInstanceMethod;
940 MarkGenericArguments (gim);
942 method = ((MethodSpecification) method).ElementMethod;
948 MethodDefinition ResolveMethodDefinition (MethodReference method)
950 MethodDefinition md = method as MethodDefinition;
952 md = method.Resolve ();
957 protected virtual void ProcessMethod (MethodDefinition method)
959 if (CheckProcessed (method))
962 Annotations.Push (method);
963 MarkType (method.DeclaringType);
964 MarkCustomAttributes (method);
965 MarkSecurityDeclarations (method);
967 MarkGenericParameterProvider (method);
969 if (IsPropertyMethod (method))
970 MarkProperty (GetProperty (method));
971 else if (IsEventMethod (method))
972 MarkEvent (GetEvent (method));
974 if (method.HasParameters) {
975 foreach (ParameterDefinition pd in method.Parameters) {
976 MarkType (pd.ParameterType);
977 MarkCustomAttributes (pd);
978 MarkMarshalSpec (pd);
982 if (method.HasOverrides) {
983 foreach (MethodReference ov in method.Overrides)
987 MarkMethodSpecialCustomAttributes (method);
989 if (method.IsVirtual)
990 _virtual_methods.Add (method);
992 MarkBaseMethods (method);
994 MarkType (method.ReturnType);
995 MarkCustomAttributes (method.MethodReturnType);
996 MarkMarshalSpec (method.MethodReturnType);
998 if (ShouldParseMethodBody (method))
999 MarkMethodBody (method.Body);
1001 DoAdditionalMethodProcessing (method);
1003 Annotations.Mark (method);
1005 ApplyPreserveMethods (method);
1009 // Allow subclassers to mark additional things when marking a method
1010 protected virtual void DoAdditionalMethodProcessing (MethodDefinition method)
1014 void MarkBaseMethods (MethodDefinition method)
1016 IList base_methods = Annotations.GetBaseMethods (method);
1017 if (base_methods == null)
1020 foreach (MethodDefinition base_method in base_methods) {
1021 if (base_method.DeclaringType.IsInterface && !method.DeclaringType.IsInterface)
1024 MarkMethod (base_method);
1025 MarkBaseMethods (base_method);
1029 bool ShouldParseMethodBody (MethodDefinition method)
1031 if (!method.HasBody)
1034 AssemblyDefinition assembly = ResolveAssembly (method.DeclaringType.Scope);
1035 return (Annotations.GetAction (method) == MethodAction.ForceParse ||
1036 (Annotations.GetAction (assembly) == AssemblyAction.Link && Annotations.GetAction (method) == MethodAction.Parse));
1039 static internal bool IsPropertyMethod (MethodDefinition md)
1041 return (md.SemanticsAttributes & MethodSemanticsAttributes.Getter) != 0 ||
1042 (md.SemanticsAttributes & MethodSemanticsAttributes.Setter) != 0;
1045 static bool IsEventMethod (MethodDefinition md)
1047 return (md.SemanticsAttributes & MethodSemanticsAttributes.AddOn) != 0 ||
1048 (md.SemanticsAttributes & MethodSemanticsAttributes.Fire) != 0 ||
1049 (md.SemanticsAttributes & MethodSemanticsAttributes.RemoveOn) != 0;
1052 static internal PropertyDefinition GetProperty (MethodDefinition md)
1054 TypeDefinition declaringType = (TypeDefinition) md.DeclaringType;
1055 foreach (PropertyDefinition prop in declaringType.Properties)
1056 if (prop.GetMethod == md || prop.SetMethod == md)
1062 static EventDefinition GetEvent (MethodDefinition md)
1064 TypeDefinition declaringType = (TypeDefinition) md.DeclaringType;
1065 foreach (EventDefinition evt in declaringType.Events)
1066 if (evt.AddMethod == md || evt.InvokeMethod == md || evt.RemoveMethod == md)
1072 protected void MarkProperty (PropertyDefinition prop)
1074 MarkCustomAttributes (prop);
1077 protected void MarkEvent (EventDefinition evt)
1079 MarkCustomAttributes (evt);
1080 MarkMethodIfNotNull (evt.AddMethod);
1081 MarkMethodIfNotNull (evt.InvokeMethod);
1082 MarkMethodIfNotNull (evt.RemoveMethod);
1085 void MarkMethodIfNotNull (MethodReference method)
1090 MarkMethod (method);
1093 protected virtual void MarkMethodBody (MethodBody body)
1095 foreach (VariableDefinition var in body.Variables)
1096 MarkType (var.VariableType);
1098 foreach (ExceptionHandler eh in body.ExceptionHandlers)
1099 if (eh.HandlerType == ExceptionHandlerType.Catch)
1100 MarkType (eh.CatchType);
1102 foreach (Instruction instruction in body.Instructions)
1103 MarkInstruction (instruction);
1106 protected virtual void MarkInstruction (Instruction instruction)
1108 switch (instruction.OpCode.OperandType) {
1109 case OperandType.InlineField:
1110 MarkField ((FieldReference) instruction.Operand);
1112 case OperandType.InlineMethod:
1113 MarkMethod ((MethodReference) instruction.Operand);
1115 case OperandType.InlineTok:
1116 object token = instruction.Operand;
1117 if (token is TypeReference)
1118 MarkType ((TypeReference) token);
1119 else if (token is MethodReference)
1120 MarkMethod ((MethodReference) token);
1122 MarkField ((FieldReference) token);
1124 case OperandType.InlineType:
1125 MarkType ((TypeReference) instruction.Operand);