예제 #1
0
        private static string GetString(IMethodInfo method, Argument[] arguments, Type[] typeArguments)
        {
            var csharp = string.Concat(method.TypeName, ".", method.Name);
            if (typeArguments.Length > 0)
            {
                csharp = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}<{1}>",
                    csharp,
                    string.Join(", ", typeArguments.Select(typeArgument => GetString(typeArgument)).ToArray()));
            }

            var format = "{0}";
            var parameterTokens = new List<string>();
            if (Command.ShowExampleValues)
            {
                format += "({1})";

                var parameters = method.MethodInfo.GetParameters();
                int parameterIndex;
                for (parameterIndex = 0; parameterIndex < arguments.Length; parameterIndex++)
                {
                    if (arguments[parameterIndex].IsGeneratedDefault)
                    {
                        continue;
                    }

                    parameterTokens.Add(string.Concat(
                        parameterIndex >= parameters.Length ? "???" : parameters[parameterIndex].Name,
                        ": ",
                        GetString(arguments[parameterIndex])));
                }

                for (; parameterIndex < parameters.Length; parameterIndex++)
                {
                    parameterTokens.Add(parameters[parameterIndex].Name + ": ???");
                }
            }

            return string.Format(CultureInfo.InvariantCulture, format, csharp, string.Join(", ", parameterTokens.ToArray()));
        }
예제 #2
0
        private static Type ResolveTypeArgument(Type typeParameter, ParameterInfo[] parameters, Argument[] arguments)
        {
            var sawNullValue = false;
            Type type = null;
            for (var index = 0; index < Math.Min(parameters.Length, arguments.Length); ++index)
            {
                if (parameters[index].ParameterType == typeParameter)
                {
                    var argument = arguments[index].Value;
                    if (argument == null)
                    {
                        sawNullValue = true;
                    }
                    else if (type == null)
                    {
                        type = argument.GetType();
                    }
                    else if (type != argument.GetType())
                    {
                        return typeof(object);
                    }
                }
            }

            if (type == null)
            {
                return typeof(object);
            }

            return sawNullValue && type.IsValueType ? typeof(object) : type;
        }
예제 #3
0
 private static IEnumerable<Type> ResolveTypeArguments(IMethodInfo method, Argument[] arguments)
 {
     var parameters = method.MethodInfo.GetParameters();
     return method.MethodInfo.GetGenericArguments().Select(typeParameter => ResolveTypeArgument(typeParameter, parameters, arguments));
 }
예제 #4
0
        private static string GetString(Argument argument)
        {
            if (argument.Value == null)
            {
                return "null";
            }

            if (argument.Value is char)
            {
                return "'" + argument.Value + "'";
            }

            var stringArgument = argument.Value as string;
            if (stringArgument != null)
            {
                if (stringArgument.Length > 50)
                {
                    return string.Concat("\"", stringArgument.Substring(0, 50), "\"...");
                }

                return string.Concat("\"", stringArgument, "\"");
            }

            return Convert.ToString(argument.Value, CultureInfo.InvariantCulture);
        }