Example #1
0
 public static void      InspectIndexer(AssemblyUsages result, PropertyDefinition propertyDef)
 {
     if (propertyDef.HasParameters == true)
     {
         AssemblyUsagesExtractor.InspectParameters(result, propertyDef.Parameters);
     }
 }
Example #2
0
 public static void      InspectParameters(AssemblyUsages result, MethodReference methodRef)
 {
     if (methodRef.HasParameters == true)
     {
         AssemblyUsagesExtractor.InspectParameters(result, methodRef.Parameters);
     }
 }
Example #3
0
        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());
                        }
                    }
                }
            }
        }