Skip to content

Instantly share code, notes, and snippets.

@daviddpatrick
Last active June 4, 2020 00:40
Show Gist options
  • Save daviddpatrick/7878ca5b23fbd671f7e1d1170a1a71ce to your computer and use it in GitHub Desktop.
Save daviddpatrick/7878ca5b23fbd671f7e1d1170a1a71ce to your computer and use it in GitHub Desktop.
Set strings properties in object to uppercase with reflection in c#
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