Skip to content

Instantly share code, notes, and snippets.

@carloswm85
Forked from pazteddy/UpperCaseAttribute.cs
Created October 11, 2025 20:17
Show Gist options
  • Save carloswm85/94690e2a22188318db1db98ccfc291d6 to your computer and use it in GitHub Desktop.
Save carloswm85/94690e2a22188318db1db98ccfc291d6 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