Created
June 25, 2020 11:26
-
-
Save di-ma-73/25a0a41fb32fb209a8ad5e2cdc20714a to your computer and use it in GitHub Desktop.
This file contains 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
/// <summary> | |
/// Represents object instance properties as a string | |
/// </summary> | |
/// <param name="o">Any object to represent its properties</param> | |
/// <returns>String { prop1: value1 prop2: value2 ... }</returns> | |
private static string InstancePropertiesToString(object o) | |
{ | |
var stringBuilder = new StringBuilder("{ "); | |
foreach (var property in o.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) | |
{ | |
stringBuilder.Append($"{property.Name}: {property.GetValue(o) ?? "null"} "); | |
} | |
stringBuilder.Append("}"); | |
return stringBuilder.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment