396 lines
9.6 KiB
C#
396 lines
9.6 KiB
C#
namespace CodeMerger.TestExamples
|
|
{
|
|
public static class TestExampleCode
|
|
{
|
|
// Ejemplo Simple
|
|
public static string SimpleMaster = @"
|
|
public class SimpleClass
|
|
{
|
|
private int _counter;
|
|
|
|
public int Counter
|
|
{
|
|
get { return _counter; }
|
|
set { _counter = value; }
|
|
}
|
|
|
|
public void Increment()
|
|
{
|
|
_counter++;
|
|
}
|
|
}";
|
|
|
|
public static string SimpleSnippet = @"
|
|
public void Decrement()
|
|
{
|
|
_counter--;
|
|
}";
|
|
|
|
// Manejo de Namespace
|
|
public static string NamespaceHandlingMaster = @"
|
|
namespace TestNamespace
|
|
{
|
|
public class MasterClass
|
|
{
|
|
public void ExistingMethod()
|
|
{
|
|
Console.WriteLine(""Original implementation"");
|
|
}
|
|
}
|
|
}";
|
|
|
|
public static string NamespaceHandlingSnippet = @"
|
|
namespace TestNamespace
|
|
{
|
|
public class MasterClass
|
|
{
|
|
public void NewMethod()
|
|
{
|
|
Console.WriteLine(""New method"");
|
|
}
|
|
}
|
|
}";
|
|
|
|
// Elementos Virtuales
|
|
public static string VirtualElementsMaster = @"
|
|
// Sin namespace ni clase
|
|
public int Calculate(int x, int y)
|
|
{
|
|
return x + y;
|
|
}";
|
|
|
|
public static string VirtualElementsSnippet = @"
|
|
// Sin namespace ni clase
|
|
public int Multiply(int x, int y)
|
|
{
|
|
return x * y;
|
|
}";
|
|
|
|
// Reemplazo de Métodos
|
|
public static string MethodReplacementMaster = @"
|
|
namespace Calculator
|
|
{
|
|
public class MathUtils
|
|
{
|
|
// Método original
|
|
public double CalculateAverage(int[] numbers)
|
|
{
|
|
int sum = 0;
|
|
foreach (var n in numbers)
|
|
sum += n;
|
|
return (double)sum / numbers.Length;
|
|
}
|
|
}
|
|
}";
|
|
|
|
public static string MethodReplacementSnippet = @"
|
|
// Mismo método con implementación mejorada
|
|
public double CalculateAverage(int[] numbers)
|
|
{
|
|
return numbers.Length > 0 ? numbers.Average() : 0;
|
|
}";
|
|
|
|
// Merge Complejo
|
|
public static string ComplexMergeMaster = @"
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace DataAccess
|
|
{
|
|
public class Repository<T> where T : class
|
|
{
|
|
private List<T> _items = new List<T>();
|
|
|
|
public void Add(T item)
|
|
{
|
|
_items.Add(item);
|
|
}
|
|
|
|
public T GetById(int id)
|
|
{
|
|
// Implementación básica
|
|
return _items[id];
|
|
}
|
|
|
|
public IEnumerable<T> GetAll()
|
|
{
|
|
return _items;
|
|
}
|
|
}
|
|
}";
|
|
|
|
public static string ComplexMergeSnippet = @"
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace DataAccess
|
|
{
|
|
public class Repository<T> where T : class
|
|
{
|
|
// Método mejorado
|
|
public T GetById(int id)
|
|
{
|
|
// Implementación mejorada con validación
|
|
if (id < 0 || id >= _items.Count)
|
|
throw new ArgumentOutOfRangeException(nameof(id));
|
|
|
|
return _items[id];
|
|
}
|
|
|
|
// Método nuevo
|
|
public void Remove(T item)
|
|
{
|
|
_items.Remove(item);
|
|
}
|
|
|
|
// Método nuevo con sobrecarga
|
|
public void Remove(int id)
|
|
{
|
|
if (id < 0 || id >= _items.Count)
|
|
throw new ArgumentOutOfRangeException(nameof(id));
|
|
|
|
_items.RemoveAt(id);
|
|
}
|
|
}
|
|
}";
|
|
|
|
// Múltiples Clases
|
|
public static string MultipleClassesMaster = @"
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Demo
|
|
{
|
|
public class Person
|
|
{
|
|
public string Name { get; set; }
|
|
public int Age { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return $""{Name}, {Age} years old"";
|
|
}
|
|
}
|
|
|
|
public class Employee : Person
|
|
{
|
|
public string Department { get; set; }
|
|
public decimal Salary { get; set; }
|
|
|
|
public decimal CalculateBonus()
|
|
{
|
|
return Salary * 0.1m;
|
|
}
|
|
}
|
|
}";
|
|
|
|
public static string MultipleClassesSnippet = @"
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Demo
|
|
{
|
|
// Modificar clase existente
|
|
public class Person
|
|
{
|
|
// Nuevo campo
|
|
private DateTime _birthDate;
|
|
|
|
// Nueva propiedad
|
|
public DateTime BirthDate
|
|
{
|
|
get { return _birthDate; }
|
|
set { _birthDate = value; Age = CalculateAge(value); }
|
|
}
|
|
|
|
// Nuevo método
|
|
private int CalculateAge(DateTime birthDate)
|
|
{
|
|
var today = DateTime.Today;
|
|
var age = today.Year - birthDate.Year;
|
|
if (birthDate > today.AddYears(-age)) age--;
|
|
return age;
|
|
}
|
|
}
|
|
|
|
// Nueva clase
|
|
public class Manager : Employee
|
|
{
|
|
public List<Employee> Team { get; set; } = new List<Employee>();
|
|
|
|
public decimal CalculateDepartmentSalary()
|
|
{
|
|
return Team.Sum(e => e.Salary) + Salary;
|
|
}
|
|
|
|
// Sobreescribir método
|
|
public new decimal CalculateBonus()
|
|
{
|
|
return Salary * 0.2m;
|
|
}
|
|
}
|
|
}";
|
|
|
|
// Clases Anidadas
|
|
public static string NestedClassesMaster = @"
|
|
using System;
|
|
|
|
namespace Configuration
|
|
{
|
|
public class ConfigManager
|
|
{
|
|
private static ConfigManager _instance;
|
|
|
|
public static ConfigManager Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
_instance = new ConfigManager();
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public class ConfigSection
|
|
{
|
|
public string Name { get; set; }
|
|
public Dictionary<string, string> Settings { get; set; } = new Dictionary<string, string>();
|
|
|
|
public string GetSetting(string key)
|
|
{
|
|
return Settings.TryGetValue(key, out var value) ? value : null;
|
|
}
|
|
}
|
|
|
|
private Dictionary<string, ConfigSection> _sections = new Dictionary<string, ConfigSection>();
|
|
|
|
public ConfigSection GetSection(string name)
|
|
{
|
|
return _sections.TryGetValue(name, out var section) ? section : null;
|
|
}
|
|
}
|
|
}";
|
|
|
|
public static string NestedClassesSnippet = @"
|
|
namespace Configuration
|
|
{
|
|
public class ConfigManager
|
|
{
|
|
// Clase anidada modificada
|
|
public class ConfigSection
|
|
{
|
|
// Nuevo método
|
|
public void SetSetting(string key, string value)
|
|
{
|
|
Settings[key] = value;
|
|
}
|
|
|
|
// Clase anidada dentro de otra clase anidada
|
|
public class EncryptedSetting
|
|
{
|
|
public string EncryptedValue { get; set; }
|
|
public string Decrypt()
|
|
{
|
|
// Simulación de desencriptación
|
|
return System.Text.Encoding.UTF8.GetString(
|
|
Convert.FromBase64String(EncryptedValue));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Nuevo método
|
|
public void AddSection(string name)
|
|
{
|
|
if (!_sections.ContainsKey(name))
|
|
_sections[name] = new ConfigSection { Name = name };
|
|
}
|
|
}
|
|
}";
|
|
|
|
// Comentarios y Formato
|
|
public static string CommentsFormatMaster = @"
|
|
using System;
|
|
|
|
namespace Documentation
|
|
{
|
|
/// <summary>
|
|
/// Representa un artículo de documentación
|
|
/// </summary>
|
|
public class DocumentItem
|
|
{
|
|
// ID único del documento
|
|
public Guid Id { get; } = Guid.NewGuid();
|
|
|
|
/// <summary>
|
|
/// Título del documento
|
|
/// </summary>
|
|
public string Title { get; set; }
|
|
|
|
/// <summary>
|
|
/// Contenido del documento
|
|
/// </summary>
|
|
public string Content { get; set; }
|
|
|
|
/// <summary>
|
|
/// Fecha de creación
|
|
/// </summary>
|
|
public DateTime Created { get; set; } = DateTime.Now;
|
|
|
|
/// <summary>
|
|
/// Formatea el documento para visualización
|
|
/// </summary>
|
|
public string FormatDocument()
|
|
{
|
|
return $""# {Title}\n\n{Content}"";
|
|
}
|
|
}
|
|
}";
|
|
|
|
public static string CommentsFormatSnippet = @"
|
|
namespace Documentation
|
|
{
|
|
public class DocumentItem
|
|
{
|
|
/// <summary>
|
|
/// Última fecha de modificación
|
|
/// </summary>
|
|
public DateTime LastModified { get; set; } = DateTime.Now;
|
|
|
|
/// <summary>
|
|
/// Etiquetas asociadas al documento
|
|
/// </summary>
|
|
public List<string> Tags { get; set; } = new List<string>();
|
|
|
|
/// <summary>
|
|
/// Verifica si el documento contiene una etiqueta específica
|
|
/// </summary>
|
|
/// <param name=""tag"">Etiqueta a buscar</param>
|
|
/// <returns>Verdadero si la etiqueta existe</returns>
|
|
public bool HasTag(string tag)
|
|
{
|
|
return Tags.Contains(tag, StringComparer.OrdinalIgnoreCase);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Formatea el documento para visualización con metadatos
|
|
/// </summary>
|
|
public string FormatDocument()
|
|
{
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine($""# {Title}"");
|
|
sb.AppendLine($""Created: {Created:yyyy-MM-dd}"");
|
|
sb.AppendLine($""Modified: {LastModified:yyyy-MM-dd}"");
|
|
|
|
if (Tags.Count > 0)
|
|
sb.AppendLine($""Tags: {string.Join(', ', Tags)}"");
|
|
|
|
sb.AppendLine();
|
|
sb.Append(Content);
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}";
|
|
}
|
|
} |