diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-05-16 23:36:33 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-05-16 23:36:33 -0500 |
| commit | d6434c02da80e499a357954f685ffedef49b4d66 (patch) | |
| tree | 3fd1022dd27fd8811dcab2136898216b1ca53b39 /src/slskd | |
| parent | 00cd66c8e74488244220f1c5e6cbb59253c022b1 (diff) | |
| download | slskd-d6434c02da80e499a357954f685ffedef49b4d66.tar.gz | |
add ToColloquialString()
Diffstat (limited to 'src/slskd')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 11 |
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> |
