aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-05-16 23:36:33 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-05-16 23:36:33 -0500
commitd6434c02da80e499a357954f685ffedef49b4d66 (patch)
tree3fd1022dd27fd8811dcab2136898216b1ca53b39 /src
parent00cd66c8e74488244220f1c5e6cbb59253c022b1 (diff)
downloadslskd-d6434c02da80e499a357954f685ffedef49b4d66.tar.gz
add ToColloquialString()
Diffstat (limited to 'src')
-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>