//Probes the methods in a type private void ProbeMethods(Type type, XmlElement typeElement, out bool methodUsesPI, out bool methodUsesIC) { methodUsesPI = false; methodUsesIC = false; MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); ArrayList retrievedPInvokeCallDetails = new ArrayList(methods.Length); foreach (MethodInfo method in methods) { try { XmlElement methodElement = this.ProbeAnalysis.CreateMethodElement(typeElement, method.Name); bool usesPI, usesIC; AnalyseMethodNativeDependencies(method, out usesPI, out usesIC); methodUsesPI = (methodUsesPI | usesPI); methodUsesIC = (methodUsesIC | usesIC); //Add details if we require them for the results if (IsResultRequired(usesPI | usesIC) && IsMethodProbe) { //Include Pinvoke details this.ProbeAnalysis.AddUsesPiAttribute(methodElement, usesPI); typeElement.AppendChild(methodElement); //Include internal call details this.ProbeAnalysis.AddUsesIcAttribute(methodElement, usesIC); typeElement.AppendChild(methodElement); //Add details from the PE probe if required... if (usesPI && this.showPInvokeDetails) { PInvokeCallDetails methodDetails = (PInvokeCallDetails)this.pinvokeDetails[PInvokeCallDetails.GetKey(type.Name, method.Name)]; retrievedPInvokeCallDetails.Add(methodDetails); this.ProbeAnalysis.AddReferencesAttribute(methodElement, methodDetails); } } } catch { Console.Error.WriteLine("Error reflecting through method: {0}", method.Name); } } }
//Add an attribute to the given node, stating whether it uses PI public void AddReferencesAttribute(XmlNode node, PInvokeCallDetails details) { node.Attributes.Append(this.CreateAttribute(DllName, details.DllName)); node.Attributes.Append(this.CreateAttribute(FunctionName, details.ExternalFunctionName)); }