using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Xunit.Abstractions;
namespace CustomerService.Tests;
public sealed class VariableTracker
{
private readonly ITestOutputHelper _testOutputHelper;
public VariableTracker(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
[Fact]
public void ScanFile()
{
string filePath =
@"C:\Users\ozkan\projects\dotnet-examples\tc-guide-getting-started-with-testcontainers-for-dotnet\TestcontainersDemo\CustomerService\CustomerService.cs";
string code = File.ReadAllText(filePath);
SyntaxTree tree = CSharpSyntaxTree.ParseText(code);
var root = (CompilationUnitSyntax)tree.GetRoot();
var variableCollector = new VariableCollector();
variableCollector.Visit(root);
_testOutputHelper.WriteLine("\nVariable Assignments:");
foreach (var assignment in variableCollector.Assignments)
{
if (assignment.Key.ToLower().Contains("command"))
_testOutputHelper.WriteLine($"Variable: {assignment.Key}, Assigned Value: {assignment.Value}");
}
}
private class VariableCollector : CSharpSyntaxWalker
{
public Dictionary<string, string> Assignments { get; } = new();
public override void VisitAssignmentExpression(AssignmentExpressionSyntax node)
{
var left = node.Left.ToString();
var right = node.Right.ToString();
Assignments[left] = right;
base.VisitAssignmentExpression(node);
}
}
}
Sunday, June 16, 2024
C# scan cs file and find variables values and names
Subscribe to:
Post Comments (Atom)
sony xperia 10 VI did not like the case
After iphone 16 I wanted to test an android and looks like sony xperia 10 VI is nice, which is 6.1 inches, but it was narrow and longer than...
-
Yeni nesil hacker'lar: Edwin Pena | Olympos Security koptum okuyunca yazılımcılar ve pazarlamacılar bu kadar kısa ve özlü bir hikayeyle ...
-
if you have wl11 ejb server and in that environment generated ejb client and deploy to wl12 it will give you this exception java.lang.NoSu...
-
yada ben okuduğumdan onu anladım fekat her zamanki gibi aleti kurarken patladı :) MS in express veya beta şeyleri genelde install aşamasında...
No comments:
Post a Comment