当前位置: 首页>>代码示例>>C#>>正文


C# IMethod.GetAllParametersSorted方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:45,代码来源:BaseRequestConstructorDecorator.cs

示例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);
                }
            }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:30,代码来源:RequestMethodResourceDecorator.cs


注:本文中的IMethod.GetAllParametersSorted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。