public static void InspectEvent(AssemblyUsages result, EventDefinition eventDef) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Event {0}", eventDef); } using (AutoIndent.Instance) { result.RegisterTypeRef(eventDef.EventType); AssemblyUsagesExtractor.InspectAttributes(result, eventDef); if (eventDef.AddMethod != null) { AssemblyUsagesExtractor.InspectMethod(result, eventDef.AddMethod); } if (eventDef.RemoveMethod != null) { AssemblyUsagesExtractor.InspectMethod(result, eventDef.RemoveMethod); } if (eventDef.InvokeMethod != null) { AssemblyUsagesExtractor.InspectMethod(result, eventDef.InvokeMethod); } } }
public static void InspectMethodReturnType(AssemblyUsages result, MethodReturnType methodReturnType) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Return {0}", methodReturnType.ReturnType); } using (AutoIndent.Instance) { result.RegisterTypeRef(methodReturnType.ReturnType); AssemblyUsagesExtractor.InspectAttributes(result, methodReturnType); } }
public static void InspectField(AssemblyUsages result, FieldDefinition fieldDef) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Field {0}", fieldDef); } using (AutoIndent.Instance) { result.RegisterTypeRef(fieldDef.FieldType); AssemblyUsagesExtractor.InspectAttributes(result, fieldDef); } }
public static void InspectInterface(AssemblyUsages result, InterfaceImplementation interfaceImpl) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Interface {0}", interfaceImpl.InterfaceType); } using (AutoIndent.Instance) { result.RegisterTypeRef(interfaceImpl.InterfaceType); AssemblyUsagesExtractor.InspectAttributes(result, interfaceImpl); } }
public static void InspectParameters(AssemblyUsages result, Collection <ParameterDefinition> parameters) { foreach (ParameterDefinition parameter in parameters) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Param {0} {1}", parameter.ParameterType, parameter.Name); } using (AutoIndent.Instance) { result.RegisterTypeRef(parameter.ParameterType); AssemblyUsagesExtractor.InspectAttributes(result, parameter); } } }
public static void InspectAttribute(AssemblyUsages result, ICustomAttribute attribute) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Attribute {0}", attribute.AttributeType); } using (AutoIndent.Instance) { result.RegisterTypeRef(attribute.AttributeType); //try //{ // // Do we need to inspect an attribute deeper? // if (attribute.HasConstructorArguments) // { // foreach (var arg in attribute.ConstructorArguments) // { // if (AssemblyUsagesExtractor.debug > 1) AssemblyUsagesExtractor.Log("Arg {0} {1}", arg.Type, arg.Value); // result.RegisterTypeRef(arg.Type); // } // } // if (attribute.HasFields) // { // foreach (var field in attribute.Fields) // { // if (AssemblyUsagesExtractor.debug > 1) AssemblyUsagesExtractor.Log("Field {0} {1} {2}", field.Name, field.Argument.Type, field.Argument.Value); // result.RegisterTypeRef(field.Argument.Type); // } // } // if (attribute.HasProperties) // { // foreach (var property in attribute.Properties) // { // if (AssemblyUsagesExtractor.debug > 1) AssemblyUsagesExtractor.Log("Property {0} {1} {2}", property.Name, property.Argument.Type, property.Argument.Value); // result.RegisterTypeRef(property.Argument.Type); // } // } //} //catch (Exception ex) //{ // if (AssemblyUsagesExtractor.debug > 0) // Console.WriteLine(ex.ToString()); //} } }
public static void InspectGenericParameter(AssemblyUsages result, GenericParameter parameter) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("GenParam {0}", parameter); } using (AutoIndent.Instance) { AssemblyUsagesExtractor.InspectAttributes(result, parameter); if (parameter.HasConstraints) { foreach (TypeReference constraint in parameter.Constraints) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Constraint {0}", constraint); } result.RegisterTypeRef(constraint); } } } }
public static void InspectProperty(AssemblyUsages result, PropertyDefinition propertyDef) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Property {0}", propertyDef); } using (AutoIndent.Instance) { result.RegisterTypeRef(propertyDef.PropertyType); AssemblyUsagesExtractor.InspectAttributes(result, propertyDef); AssemblyUsagesExtractor.InspectIndexer(result, propertyDef); if (propertyDef.GetMethod != null) { AssemblyUsagesExtractor.InspectMethod(result, propertyDef.GetMethod); } if (propertyDef.SetMethod != null) { AssemblyUsagesExtractor.InspectMethod(result, propertyDef.SetMethod); } } }
public static void InspectMethod(AssemblyUsages result, MethodDefinition methodDef) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Method {0}", methodDef); } using (AutoIndent.Instance) { AssemblyUsagesExtractor.InspectAttributes(result, methodDef); AssemblyUsagesExtractor.InspectSecurityDeclarations(result, methodDef); AssemblyUsagesExtractor.InspectGenericParameters(result, methodDef); AssemblyUsagesExtractor.InspectParameters(result, methodDef); AssemblyUsagesExtractor.InspectMethodReturnType(result, methodDef.MethodReturnType); if (methodDef.HasBody) { if (methodDef.Body.HasVariables) { foreach (VariableDefinition variable in methodDef.Body.Variables) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Var {0} {1}", variable.Index, variable.VariableType); } result.RegisterTypeRef(variable.VariableType); } } foreach (Instruction il in methodDef.Body.Instructions) { if (il.OpCode == OpCodes.Ldsfld || il.OpCode == OpCodes.Ldsflda || il.OpCode == OpCodes.Stsfld || il.OpCode == OpCodes.Ldfld || il.OpCode == OpCodes.Ldflda || il.OpCode == OpCodes.Stfld) { FieldReference fieldRef = il.Operand as FieldReference; if (result.RegisterFieldRef(fieldRef) == true) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Use Field {0}", fieldRef.FullName); } else if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Cache Use Field {0}", fieldRef.FullName); } } } else if (il.OpCode == OpCodes.Call || il.OpCode == OpCodes.Callvirt || il.OpCode == OpCodes.Calli || il.OpCode == OpCodes.Newobj || il.OpCode == OpCodes.Jmp || il.OpCode == OpCodes.Ldftn || il.OpCode == OpCodes.Ldvirtftn) { MethodReference methodRef = il.Operand as MethodReference; if (methodRef != null) { if (result.RegisterMethodRef(methodRef) == true) { if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Call {0}", methodRef.FullName); } using (AutoIndent.Instance) { AssemblyUsagesExtractor.InspectParameters(result, methodRef); } } else if (AssemblyUsagesExtractor.debug > 1) { AssemblyUsagesExtractor.Log("Cache Call {0}", methodRef.FullName); } } } else if (il.OpCode == OpCodes.Castclass || il.OpCode == OpCodes.Isinst || il.OpCode == OpCodes.Box || il.OpCode == OpCodes.Newarr || il.OpCode == OpCodes.Ldobj || il.OpCode == OpCodes.Stobj || il.OpCode == OpCodes.Cpobj || il.OpCode == OpCodes.Unbox || il.OpCode == OpCodes.Unbox_Any || il.OpCode == OpCodes.Initobj || il.OpCode == OpCodes.Sizeof || il.OpCode == OpCodes.Refanyval || il.OpCode == OpCodes.Mkrefany || il.OpCode == OpCodes.Ldelema || il.OpCode == OpCodes.Ldelem_Any || il.OpCode == OpCodes.Constrained) { result.RegisterTypeRef(il.Operand as TypeReference); } else if (il.OpCode == OpCodes.Ldtoken) { TypeReference typeRef = il.Operand as TypeReference; if (typeRef != null) { result.RegisterTypeRef(typeRef); continue; } FieldReference fieldRef = il.Operand as FieldReference; if (fieldRef != null) { result.RegisterFieldRef(fieldRef); continue; } Debug.LogError("UNHANDLED OpCodes.Ldtoken " + il.Operand.GetType()); } } } } }