-
-
Save carloswm85/94690e2a22188318db1db98ccfc291d6 to your computer and use it in GitHub Desktop.
Atributo personalizado para convertir un texto a mayúsculas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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