.NET / C # - Reflection - System.IO.File ever used

Is there a way to use reflection to completely “scan” the assembly to see if System.IO.File or System.IO.Directory is being used? These are just examples of classes. Just wondering if there is a way to do this through reflection (versus code analysis).

Update : see comments

+3
source share
6 answers

As Tommy Carlier said, this is very easy to do with Cecil .

using Mono.Cecil;

// ..

var assembly = AssemblyFactory.GetAssembly ("Foo.Bar.dll");
var module = assembly.MainModule;

bool references_file = module.TypeReferences.Contains ("System.IO.File");
+6
source

The fantastic NDepend tool will provide you with such dependency information.

DLL NDepend , , CQL:

SELECT TYPES WHERE IsDirectlyUsing "System.IO.File"

, .

+3

Mono Cecil . Cecil , IL- ( ).

+1

, , :

http://gist.github.com/raw/104001/5ed01ea8a3bf7c8ad669d836de48209048d02b96/MethodBaseRocks.cs

MethodInfo/ConstructorInfo, ILByteArray Instruction.

, MethodInfo/ConstructorInfo , Instruction MethodInfo/ConstructorInfo , - Instruction Operand, MemberInfo, DeclaringType, .

+1

Assembly.GetExecutingAssembly().GetReferencedAssemblies(). , . System.CodeDom. .

0

.NET Reflector - . , .

ReSharper . - , .NET Framework.

0

Source: https://habr.com/ru/post/1712235/


All Articles