What term describes parsing code (c#) to trace references?

Viewed 44

I want to trace C# code, and I'm not sure of the technical terminology to Google the approach.

Pretend I want to understand which parts of my code depend upon a stored procedure.

Pseudo-code:

  • FIND the proc name in visual studio, and get result(s).
  • for each result, identify the entity (constant or method) the result occurs in.
  • for each entity, follow references (recursively) to tail.

Example:

  • FIND "UpsertFoo_spr" (result: string)
  • String exists in "FooRepository.Save()"
  • "FooRepository.Save()" is called by "FooController.SaveFoo()" and "FooController.ReassignFoo()"
  • "FooController.SaveFoo()" is called by "[FooDetails.aspx].Save_OnClick()"
  • "FooController.ReassignFoo()" is called by "[FooManager.aspx].Reassign_OnClick()"

If you can just tell me what this is called, I can Google solutions appropriate to my context. Thanks!

1 Answers

This is generally called "Code Analysis" and can come in various forms:

  • Runtime code analysis (analyzing stack traces or exception unwinding)
  • Static (source) code analysis (analyze source code or abstract syntax trees)
  • Classification (big-O notation, algorithm classification, etc)

Recent versions of the .NET Framework have a rich compiler and code analysis framework known as the .NET Compiler Platform, often referred to as Roslyn, that makes it easier to analyze source code, and even integrate these analyses into Visual Studio via Quick Fix context menu, refactoring, compiler warnings, debugger visualizations, etc.

https://docs.microsoft.com/en-us/visualstudio/extensibility/getting-started-with-roslyn-analyzers?view=vs-2019

Related