-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved TypeNameFormatter and more cleanup. All tests passed
- Loading branch information
1 parent
a7ab501
commit 2f42bb7
Showing
4 changed files
with
81 additions
and
85 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace LightInject; | ||
|
||
/// <summary> | ||
/// [assembly: DebuggerDisplay("{LightInject.TypeNameFormatter.GetHumanFriendlyTypeName(this)}", Target = typeof(Type))] | ||
/// </summary> | ||
public static class TypeNameFormatter | ||
{ | ||
public static string GetHumanFriendlyTypeName(Type type) | ||
{ | ||
StringBuilder humanFriendlyName = new StringBuilder(); | ||
if (type.IsGenericType && !type.IsGenericTypeDefinition) | ||
{ | ||
|
||
humanFriendlyName.Append(type.Name.Substring(0, type.Name.IndexOf('`'))); | ||
humanFriendlyName.Append('<'); | ||
foreach (Type argument in type.GenericTypeArguments) | ||
{ | ||
humanFriendlyName.Append(GetHumanFriendlyTypeName(argument)); | ||
humanFriendlyName.Append(", "); | ||
} | ||
humanFriendlyName.Remove(humanFriendlyName.Length - 2, 2); | ||
humanFriendlyName.Append('>'); | ||
} | ||
else if (type.IsGenericTypeDefinition) | ||
{ | ||
humanFriendlyName.Append(type.Name.Substring(0, type.Name.IndexOf('`'))); | ||
humanFriendlyName.Append('<'); | ||
foreach (Type parameter in type.GetGenericArguments()) | ||
{ | ||
humanFriendlyName.Append(parameter.Name); | ||
humanFriendlyName.Append(", "); | ||
} | ||
humanFriendlyName.Remove(humanFriendlyName.Length - 2, 2); | ||
humanFriendlyName.Append('>'); | ||
} | ||
else | ||
{ | ||
humanFriendlyName.Append(type.Name); | ||
} | ||
return humanFriendlyName.ToString(); | ||
} | ||
} |
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