PowerAssert.Infrastructure.ExpressionParser.NameOfType C# (CSharp) Метод

NameOfType() статический приватный Метод

static private NameOfType ( Type t ) : string
t System.Type
Результат string
        internal static string NameOfType(Type t)
        {
            if (t.IsGenericType)
            {
                var typeArgs = t.GetGenericArguments().Select(NameOfType).ToList();
                var name = IsAnonymousType(t) ? "$Anonymous" : t.Name.Split('`')[0];
                return string.Format("{0}<{1}>", name, string.Join(", ", typeArgs));
            }
            else
            {
                return Util.Aliases.ContainsKey(t) ? Util.Aliases[t] : t.Name;
            }
        }

Usage Example

Пример #1
0
        internal static string FormatObject(object value)
        {
            if (value == null)
            {
                return("null");
            }
            if (value is string)
            {
                return("\"" + value + "\"");
            }
            if (value is char)
            {
                return("'" + value + "'");
            }

            var exception = value as Exception;

            if (exception != null)
            {
                return("{" + exception.GetType().Name + "}");
            }

            var type = value.GetType();

            if (type.GetTypeInfo().IsGenericType&& type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
            {
                var k = type.GetRuntimeProperty("Key").GetValue(value, null);
                var v = type.GetRuntimeProperty("Value").GetValue(value, null);
                return(String.Format("{{{0}:{1}}}", FormatObject(k), FormatObject(v)));
            }
            if (type.GetTypeInfo().ImplementedInterfaces
                .Where(i => i.IsConstructedGenericType)
                .Any(i => i.GetGenericTypeDefinition() == typeof(IGrouping <,>)))
            {
                var k = type.GetRuntimeProperty("Key").GetValue(value, null);
                return(String.Format("{{{0}:{1}}}", FormatObject(k), FormatEnumerable(value)));
            }
            if (value is Type)
            {
                return("typeof(" + ExpressionParser.NameOfType((Type)value) + ")");
            }
            if (value is Delegate)
            {
                var del = (Delegate)value;


                return(String.Format("delegate {0}, type: {2} ({1})", ExpressionParser.NameOfType(del.GetType()), String.Join(", ", del.GetMethodInfo().GetParameters().Select(x => ExpressionParser.NameOfType(x.ParameterType))), ExpressionParser.NameOfType(del.GetMethodInfo().ReturnType)));
            }
            if (value is IEnumerable)
            {
                return(FormatEnumerable(value));
            }
            return(value.ToString());
        }
All Usage Examples Of PowerAssert.Infrastructure.ExpressionParser::NameOfType