From d6434c02da80e499a357954f685ffedef49b4d66 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 16 May 2021 23:36:33 -0500 Subject: add ToColloquialString() --- src/slskd/Common/Extensions.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 @@ -43,6 +43,17 @@ namespace slskd return string.Join(separator, parts.Take(parts.Length - 1)); } + /// + /// 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. + /// + /// The type for which the colloquial name should be created. + /// A "pretty" string representation of the provided Type. + public static string ToColloquialString(this Type type) + { + return !type.IsGenericType ? type.Name : type.Name.Split('`')[0] + "<" + string.Join(", ", type.GetGenericArguments().Select(a => a.ToColloquialString())) + ">"; + } + /// /// Returns the SHA1 hash of the given string. /// -- cgit v1.2.3