Hello -

you might want to take a look at my ".Net Architecture Checker" at 
http://sourceforge.net/projects/dotnetarchitect/ - maybe it helps you either to 
solve your problems or to see the code to find all "usages".
(The documentation is not yet up-to-date, as we have just moved from textual 
IL-file parsing to Cecil).

Best Regards
Harald M. Mueller

-------- Original-Nachricht --------
> Datum: Sun, 17 Jan 2010 20:23:20 -0800 (PST)
> Von: Andrew <[email protected]>
> An: mono-cecil <[email protected]>
> Betreff: [mono-cecil] Finding all the dependencies of a type in an assembly

> Hi,
> For each type in an assembly, I want to get a list of all the types
> that the given type is dependent on, i.e. those that are used as
> fields, properties, in methods, and anywhere else the type could use
> them. I want to include any types that happen to be defined in the
> same assembly.
> 
> Basically, the idea is to load an assembly, and for each type defined
> in the assembly, list all the type dependencies.
> 
> So far I have been able to get a list of used types from the assembly,
> and some dependencies, with
> 
> FileInfo f = new FileInfo("SomeAssembly.dll");
> AssemblyDefinition assemDef = AssemblyFactory.GetAssembly
> (f.FullName);
> 
> foreach(ModuleDefinition mDef in assemDef.Modules){
>       foreach (TypeDefinition type in mDef.Types) {
>               if(!"<Module>".Equals(type.FullName)){
>                       Console.WriteLine (type.Name+" ["+type.Namespace+"]");
> 
>                       foreach(MethodDefinition method in type.Methods)
>                       {
>                               if(method.HasBody){
>                                       foreach(Instruction instr in 
> method.Body.Instructions){
>                                               if(instr.OpCode.OperandType == 
> OperandType.InlineType){
>                                                       Console.WriteLine 
> ("\tUses type "+instr.Operand);
>                                               }
>                                       }
>                               }
>                       }
>               }
>       }
> }
> 
> but this doesn't work very well, as it doesn't list types defined in
> the assembly. It also misses a lot of types used in the code.
> 
> The plan is to have this dependency generator the basis of a
> dependency analyser. Are there any tools that can do this and the
> source code is available? I know of some such as reflector and
> NDepend, but I cannot see how they generate the list, as they do not
> seem to be open source.
> 
> I will have a look at Gendarme next, and see if that can help, but it
> seems focused in a different area.
> 
> Is there any way of getting this information using Cecil, or an other
> libraries, or am I going to have to go through the IL line by line
> looking for opcodes?

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
-- 
--
mono-cecil

Reply via email to