Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- namespace Placebo.Internal
- {
- internal static class ReflectionExtensions
- {
- public static string GetFriendlyName(this Type type)
- {
- if (type == null) return "<null>";
- var typeName = type.Name;
- if (!type.IsGenericType)
- return typeName;
- var length = typeName.IndexOf('`');
- if (length < 0) length = typeName.Length;
- return new StringBuilder()
- .Append(typeName, 0, length)
- .Append('<')
- .Append(string.Join(",", type.GetGenericArguments().Select(GetFriendlyName)))
- .Append('>')
- .ToString();
- }
- public static string GetObjectFriendlyName(this object subject)
- {
- if (subject == null) return "<null>";
- return string.Format(
- "{0}@{1:x}",
- subject.GetType().GetFriendlyName(),
- RuntimeHelpers.GetHashCode(subject));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement