Comments
6 comments
-
I also am trying to leverage Analyze programmatically. Does anyone have an example of this? (Or a definitive answer as to why this isn't possible?)
Regards,
Scott Koland. -
I've dug around a bit and don't really see any way to tap into the Analyze functionality.
What type of extensions to the Analyze functionality are you guys thinking about? -
Hi Jason,
Specifically, I am trying to call Analyze -> Instantiated By for every class in a selected namespace. My goal is to find all instance calls of a namespace in a large codebase (hundreds of objects), and output to the Clipboard or a text file. [Ideally, I'll also add filtering to the iterator - I'm looking for a grouping of specific namespaces that are referenced.]
Basically, I'm trying to do the same thing in code as your PowerCommands Add-In in the "Export Tree as Text" option. But without opening each Analyzer window on each class. [Thanks for all the excellent documentation on your site, btw.]
Something like the following:StringBuilder resultSet; foreach(var type in selectedNamespaceItem.Types) { if(type is IType){ resultSet.Append( Analyze(type) ); } }
But I'm not sure if it is possible or how to go about calling Analyze in code.
Thanks, Scott. -
Hmm, I'd say its doable with the Query Editor. Let me see if I can figure out the query needed.
So basically you're looking for any field, method, property, event that has a type reference to a specific type in a given namespace?
The Query Editor doesn't specifically support queries for a selected namespace, but you can type it in the query editor.
Give me a day and I'll see if i can figure it out for you. -
Here's a query to find where an object is instatianted. If you run this example in the Query Editor, it should find any place the System.IO.Stream type is instantiated in the System.Net namespace.
(from a in AssemblyManager.Assemblies.Cast<IAssembly>() from m in a.Modules.Cast<IModule>() from t in m.Types.Cast<ITypeDeclaration>() from mt in t.Methods.Cast<IMethodDeclaration>() where ((ITypeReference)mt.DeclaringType).Namespace == "System.Net" where mt.Body is IMethodBody from i in ((IMethodBody)mt.Body).Instructions.Cast<IInstruction>() where i != null && i.Value != null && i.Value is IMemberReference && ((IMemberReference)i.Value).Name == ".ctor" && ((IMemberReference)i.Value).DeclaringType is ITypeReference && ((ITypeReference)((IMemberReference)i.Value).DeclaringType).Name == "Stream" && ((ITypeReference)((IMemberReference)i.Value).DeclaringType).Namespace == "System.IO" select mt).Distinct()
There are 3 things you'll need to change:
1. Namespace filter (in example above = "System.Net")
2. Type name (in example above = "Stream")
3. Type namespace (in example above = "System.IO")
Let me know if it doesn't find everything you need - it looks for calls to the class's constructor so it won't look at fields or return types. -
I updated query editor to do Import/Export of queries. The query I mentioned above is available for import from http://jasonhaley.com/files/InstantiatedByFilterByNamespace.xml
You will need to download the latest version of the Reflector.PowerCommands addin (v1.3.3.36545).
Add comment
Please sign in to leave a comment.
is it possible to access the Analyze method of Reflector programatically?
Yours,
Alois Kraus