Пример #1
0
        private StringBuilder AppendParameter(StringBuilder buf, ParameterDefinition parameter)
        {
            if (parameter.ParameterType is ByReferenceType)
            {
                if (parameter.IsOut)
                {
                    buf.Append("out ");
                }
                else
                {
                    buf.Append("ref ");
                }
            }
            if (parameter.HasCustomAttributes)
            {
                var isParams = parameter.CustomAttributes.Any(ca => ca.AttributeType.Name == "ParamArrayAttribute");
                if (isParams)
                {
                    buf.AppendFormat("params ");
                }
            }

            var context        = AttributeParserContext.Create(parameter);
            var isNullableType = context.IsNullable();

            buf.Append(GetTypeName(parameter.ParameterType, context));
            buf.Append(GetTypeNullableSymbol(parameter.ParameterType, isNullableType));
            buf.Append(" ");
            buf.Append(parameter.Name);

            if (parameter.HasDefault && parameter.IsOptional && parameter.HasConstant)
            {
                var ReturnVal = new AttributeFormatter().MakeAttributesValueString(parameter.Constant, parameter.ParameterType);
                buf.AppendFormat(" = {0}", ReturnVal == "null" ? "default" : ReturnVal);
            }
            return(buf);
        }