aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/slskd/Common/Extensions.cs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs
index 4e08ed02..4bf9f919 100644
--- a/src/slskd/Common/Extensions.cs
+++ b/src/slskd/Common/Extensions.cs
@@ -44,6 +44,17 @@ namespace slskd
}
/// <summary>
+ /// Returns a "pretty" string representation of the provided Type; specifically, corrects the naming of generic Types
+ /// and appends the type parameters for the type to the name as it appears in the code editor.
+ /// </summary>
+ /// <param name="type">The type for which the colloquial name should be created.</param>
+ /// <returns>A "pretty" string representation of the provided Type.</returns>
+ public static string ToColloquialString(this Type type)
+ {
+ return !type.IsGenericType ? type.Name : type.Name.Split('`')[0] + "<" + string.Join(", ", type.GetGenericArguments().Select(a => a.ToColloquialString())) + ">";
+ }
+
+ /// <summary>
/// Returns the SHA1 hash of the given string.
/// </summary>
/// <param name="str">The string to hash.</param>