50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using NetDocsForLLM.Models;
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace NetDocsForLLM.Services
|
|
{
|
|
public interface IAssemblyAnalyzer
|
|
{
|
|
AssemblyModel LoadAssembly(string filePath);
|
|
}
|
|
|
|
public class AssemblyAnalyzer : IAssemblyAnalyzer
|
|
{
|
|
public AssemblyModel LoadAssembly(string filePath)
|
|
{
|
|
if (string.IsNullOrEmpty(filePath))
|
|
throw new ArgumentException("Ruta de archivo no válida", nameof(filePath));
|
|
|
|
if (!File.Exists(filePath))
|
|
throw new FileNotFoundException($"No se encontró el archivo: {filePath}");
|
|
|
|
var assemblyModel = new AssemblyModel(filePath);
|
|
|
|
try
|
|
{
|
|
// Load assembly
|
|
var assembly = Assembly.LoadFrom(filePath);
|
|
assemblyModel.LoadedAssembly = assembly;
|
|
assemblyModel.Name = assembly.GetName().Name;
|
|
assemblyModel.Version = assembly.GetName().Version;
|
|
|
|
// Check for XML documentation
|
|
var xmlFilePath = Path.ChangeExtension(filePath, ".xml");
|
|
if (File.Exists(xmlFilePath))
|
|
{
|
|
assemblyModel.HasXmlDocumentation = true;
|
|
assemblyModel.XmlDocPath = xmlFilePath;
|
|
}
|
|
|
|
return assemblyModel;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new InvalidOperationException($"Error al cargar el ensamblado: {ex.Message}", ex);
|
|
}
|
|
}
|
|
}
|
|
}
|