Skip to content

Instantly share code, notes, and snippets.

@pazteddy
Created May 14, 2025 19:28
Show Gist options
  • Save pazteddy/2ff35d308e5fd6435096f924a2b0f429 to your computer and use it in GitHub Desktop.
Save pazteddy/2ff35d308e5fd6435096f924a2b0f429 to your computer and use it in GitHub Desktop.
Atributo personalizado para convertir un texto a mayúsculas
[AttributeUsage(AttributeTargets.Property)]
public class UpperCaseAttribute : Attribute
{
}
public static class AttributeProcessor
{
public static void ApplyUpperCase(object obj)
{
var props = obj.GetType().GetProperties();
foreach (var prop in props)
{
// Verifica que la propiedad tenga el atributo y sea tipo string
if (prop.PropertyType == typeof(string) &&
Attribute.IsDefined(prop, typeof(UpperCaseAttribute)))
{
var value = prop.GetValue(obj) as string;
if (!string.IsNullOrWhiteSpace(value))
{
// Establece el valor en mayúsculas
prop.SetValue(obj, value.ToUpper());
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment