本文整理汇总了C#中IMethod.GetAllParametersSorted方法的典型用法代码示例。如果您正苦于以下问题:C# IMethod.GetAllParametersSorted方法的具体用法?C# IMethod.GetAllParametersSorted怎么用?C# IMethod.GetAllParametersSorted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMethod
的用法示例。
在下文中一共展示了IMethod.GetAllParametersSorted方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRequestParameters
internal void AddRequestParameters(CodeTypeDeclaration resourceClass,
IMethod request,
CodeConstructor constructor,
bool addOptional)
{
if (request.Parameters == null)
{
return; // Nothing to do here.
}
foreach (IParameter parameter in request.GetAllParametersSorted())
{
if (!addOptional && !parameter.IsRequired)
{
continue;
}
// Retrieve parameter name and type.
string name = parameter.Name;
CodeTypeReference type = ResourceBaseGenerator.GetParameterTypeReference(
resourceClass, parameter);
// Generate valid names for the parameter and the field.
IEnumerable<string> usedWords = from IParameter p in request.Parameters.Values select p.Name;
string parameterName = GeneratorUtils.GetParameterName(parameter, usedWords.Without(parameter.Name));
string fieldName = GeneratorUtils.GetFieldName(name, Enumerable.Empty<string>());
// Add the constructor parameter. (e.g. JsonSchema schema)
var newParameter = new CodeParameterDeclarationExpression(type, parameterName);
constructor.Parameters.Add(newParameter);
// Make the parameter optional if required.
if (!parameter.IsRequired)
{
var optionalTypeRef = new CodeTypeReference(typeof(OptionalAttribute));
newParameter.CustomAttributes.Add(new CodeAttributeDeclaration(optionalTypeRef));
}
// Add the initialization expression (e.g. this.schema = schema;)
var initStatement = new CodeAssignStatement();
initStatement.Left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName);
initStatement.Right = new CodeVariableReferenceExpression(parameterName);
constructor.Statements.Add(initStatement);
}
}
示例2: AddDeclaredParameters
internal void AddDeclaredParameters(CodeTypeDeclaration classDeclaration,
IMethod method,
CodeMemberMethod member,
CodeExpressionCollection constructorParameters,
bool addOptionalParameters)
{
if (method.Parameters == null)
{
return;
}
// Add all parameters to the method.
foreach (var param in method.GetAllParametersSorted())
{
if (!addOptionalParameters && !param.IsRequired)
{
continue;
}
// Generate a safe parameter name which was not yet used.
// Also exclude method name as VB can not have parameterName the same as method name.
string parameterName = GeneratorUtils.GetParameterName(
param, method.Parameters.Keys.Without(param.Name).Concat(method.Name));
// Declare the parameter, and add it to the list of constructor parameters of the request class.
member.Parameters.Add(DeclareInputParameter(classDeclaration, param, method));
constructorParameters.Add(new CodeVariableReferenceExpression(parameterName));
AddParameterComment(commentCreator, member, param, parameterName);
}
}