Created
April 22, 2026 09:32
-
-
Save r1d3rzz/78a3e68cc2f6ff81f7360614faffe6d5 to your computer and use it in GitHub Desktop.
refractor obj properties 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
| // 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