in plugin-dotnet-agent/src/main/csharp/TeamCity.Dotnet.TestSuppressor/TeamCity.Dotnet.TestSuppressor/Domain/Patching/AssemblyPatcher.cs [32:67]
public async Task<AssemblyPatchingResult> TryPatchAsync(IFileInfo assemblyFile, IAssemblyPatchingCriteria criteria)
{
_logger.LogInformation("Trying to patch assembly: {AssemblyFile}", assemblyFile.FullName);
var mutationResult = AssemblyMutationResult.Empty;
var modifiedAssemblyResult = await TryModifyAssembly(assemblyFile.FullName, async assembly =>
{
var mutator = SelectMutator(criteria);
mutationResult = await mutator.MutateAsync(assembly, criteria);
return !mutationResult.IsEmpty;
});
if (modifiedAssemblyResult.IsModified && !mutationResult.IsEmpty)
{
_logger.LogInformation(
"Assembly patched successfully: {OriginalAssemblyPath}, backup: {BackupAssemblyPath}, symbols: {HasSymbols}\n" +
"Affected {AffectedTypes} type(s) and {AffectedMethods} method(s)",
modifiedAssemblyResult.OriginalAssemblyPath,
modifiedAssemblyResult.BackupAssemblyPath,
modifiedAssemblyResult.HasBackupSymbols,
mutationResult.AffectedTypes,
mutationResult.AffectedMethods
);
return AssemblyPatchingResult.Patched(
assemblyPath: modifiedAssemblyResult.OriginalAssemblyPath,
backupAssemblyPath: modifiedAssemblyResult.BackupAssemblyPath,
symbolsPath: modifiedAssemblyResult.OriginalSymbolsPath,
backupSymbolsPath: modifiedAssemblyResult.BackupSymbolsPath,
mutationResult: mutationResult
);
}
_logger.LogInformation("No changes were made to the assembly: {AssemblyFile}", assemblyFile.FullName);
return AssemblyPatchingResult.NotPatched(assemblyFile.FullName);
}