Example #1
0
        public string Format(IFormatorRequest formatorRequest)
        {
            if ((formatorRequest is ParameterFormatorRequest) == false)
            {
                throw new ArgumentException($"ParameterFormator exepects {typeof(ParameterFormatorRequest)}");
            }

            ParameterFormatorRequest parameterFormatorRequest = (ParameterFormatorRequest)formatorRequest;

            StringBuilder sb = new StringBuilder();

            var parameter = parameterFormatorRequest.Parameter;

            if (parameter.IsOut)
            {
                sb.Append("out ");
            }

            if (parameter.ParameterType.IsGenericType)
            {
                var genericArguments = parameter.ParameterType.GetGenericArguments();

                var genericArgumentsJoin = string.Join(", ", genericArguments.Select(genericType => genericType.Name));

                var typeName = parameter.ParameterType.Name.Replace($"`{genericArguments.Length}", "");

                sb.Append($"{typeName}<{genericArgumentsJoin}>");
            }
            else
            {
                sb.Append(parameter.ParameterType.Name.Replace("&", ""));
            }

            sb.Append(" ");

            sb.Append(parameter.Name);

            if (parameter.HasDefaultValue)
            {
                sb.Append($" = {parameter.DefaultValue}");
            }

            return(sb.ToString());
        }
        public string Format(IFormatorRequest formatorRequest)
        {
            if ((formatorRequest is ListOfParameterFormatorRequest) == false)
            {
                throw new ArgumentException($"Parameter formator only takes a {typeof(ListOfParameterFormatorRequest).Name}");
            }

            ListOfParameterFormatorRequest listOfParameterFormatorRequest = (ListOfParameterFormatorRequest)formatorRequest;

            var formatedParamaters = listOfParameterFormatorRequest.Parameters.Select(param =>
            {
                IFormatorRequest parameterFormatorRequest = new ParameterFormatorRequest
                {
                    Parameter = param
                };

                IFormator formator = m_formatorFactory.CreateFormator(parameterFormatorRequest);

                return(formator.Format(parameterFormatorRequest));
            });

            return(string.Join(", ", formatedParamaters));
        }