Last active
June 4, 2020 00:40
-
-
Save daviddpatrick/7878ca5b23fbd671f7e1d1170a1a71ce to your computer and use it in GitHub Desktop.
Set strings properties in object to uppercase with reflection in c#
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
var obj = new Class(); | |
obj.GetType().GetProperties().ForEach(p => | |
{ | |
if (p.PropertyType == typeof(string) && p.GetValue(obj) != null) | |
p.SetValue(obj, p.GetValue(obj).ToString().ToUpper()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment