Skip to content

Instantly share code, notes, and snippets.

@r1d3rzz
Created April 22, 2026 09:32
Show Gist options
  • Select an option

  • Save r1d3rzz/78a3e68cc2f6ff81f7360614faffe6d5 to your computer and use it in GitHub Desktop.

Select an option

Save r1d3rzz/78a3e68cc2f6ff81f7360614faffe6d5 to your computer and use it in GitHub Desktop.
refractor obj properties in c#
// sample
public static void SetProperty(object obj, string propertyName, object value)
{
var prop = obj.GetType().GetProperty(propertyName);
if (prop != null && prop.CanWrite)
{
prop.SetValue(obj, value);
}
}
// usage
SetProperty(user, "Age", 12);
SetProperty(user, "Name", "mgmg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment