From fbdcc2793288ee2e83971c0db72eb7927677bdb9 Mon Sep 17 00:00:00 2001 From: stankovski Date: Fri, 27 May 2016 15:31:49 -0700 Subject: [PATCH] Addressed fxcop issues --- .../CSharp/CSharp/GlobalSuppressions.cs | 5 +- .../TemplateModels/MethodTemplateModel.cs | 48 ++++++------------- .../Templates/ExtensionMethodTemplate.cshtml | 2 +- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/AutoRest/Generators/CSharp/CSharp/GlobalSuppressions.cs b/AutoRest/Generators/CSharp/CSharp/GlobalSuppressions.cs index e4ed9bd8b4441..10c7165b62b24 100644 --- a/AutoRest/Generators/CSharp/CSharp/GlobalSuppressions.cs +++ b/AutoRest/Generators/CSharp/CSharp/GlobalSuppressions.cs @@ -64,8 +64,6 @@ MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.TemplateModels.ClientModelExtensions.#AppendConstraintValidations(System.String,System.Collections.Generic.Dictionary`2,Microsoft.Rest.Generator.Utilities.IndentedStringBuilder)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.MethodTemplateModel.#.ctor(Microsoft.Rest.Generator.ClientModel.Method,Microsoft.Rest.Generator.ClientModel.ServiceClient)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.MethodTemplateModel.#.ctor(Microsoft.Rest.Generator.ClientModel.Method,Microsoft.Rest.Generator.ClientModel.ServiceClient)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.ModelTemplateModel.#.ctor(Microsoft.Rest.Generator.ClientModel.CompositeType)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.MethodTemplateModel.#GroupedParameterTemplateModels")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.MethodTemplateModel.#LogicalParameterTemplateModels")] @@ -76,4 +74,7 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.ClientModelExtensions.#CheckNull(System.String,System.String)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.ClientModelExtensions.#ValidateType(Microsoft.Rest.Generator.ClientModel.IType,Microsoft.Rest.Generator.Utilities.IScopeProvider,System.String,System.Collections.Generic.Dictionary`2)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.AppendLine(System.String)", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.ClientModelExtensions.#AppendConstraintValidations(System.String,System.Collections.Generic.Dictionary`2,Microsoft.Rest.Generator.Utilities.IndentedStringBuilder)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.MethodTemplateModel.#.ctor(Microsoft.Rest.Generator.ClientModel.Method,Microsoft.Rest.Generator.ClientModel.ServiceClient,Microsoft.Rest.Generator.CSharp.SyncMethodsGenerationMode)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.MethodTemplateModel.#.ctor(Microsoft.Rest.Generator.ClientModel.Method,Microsoft.Rest.Generator.ClientModel.ServiceClient,Microsoft.Rest.Generator.CSharp.SyncMethodsGenerationMode)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.MethodTemplateModel.#GetAsyncMethodInvocationArgs(System.String,System.String)")] diff --git a/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs b/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs index 0ba0a8d759dfd..8e99ee936e928 100644 --- a/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs +++ b/AutoRest/Generators/CSharp/CSharp/TemplateModels/MethodTemplateModel.cs @@ -59,33 +59,8 @@ public string FailureStatusCodePredicate } return "!_httpResponse.IsSuccessStatusCode"; } - } - - /// - /// Generate the method parameter declarations for the sync extension - /// - public string SyncMethodParameterDeclaration - { - get - { - List declarations = new List(); - foreach (var parameter in LocalParameters) - { - string format = (parameter.IsRequired ? "{0} {1}" : "{0} {1} = {2}"); - string defaultValue = string.Format(CultureInfo.InvariantCulture, "default({0})", parameter.DeclarationExpression); - if (parameter.DefaultValue != null && parameter.Type is PrimaryType) - { - defaultValue = parameter.DefaultValue; - } - declarations.Add(string.Format(CultureInfo.InvariantCulture, - format, parameter.DeclarationExpression, parameter.Name, defaultValue )); - } - - return string.Join(", ", declarations); - } - } - - + } + /// /// Generate the method parameter declaration for async methods and extensions /// @@ -101,18 +76,25 @@ public virtual string GetAsyncMethodParameterDeclaration() /// Generated string of parameters public virtual string GetSyncMethodParameterDeclaration(bool addCustomHeaderParameters) { - var declarations = this.SyncMethodParameterDeclaration; - - if (!string.IsNullOrEmpty(declarations) && addCustomHeaderParameters) + List declarations = new List(); + foreach (var parameter in LocalParameters) { - declarations += ", "; + string format = (parameter.IsRequired ? "{0} {1}" : "{0} {1} = {2}"); + string defaultValue = string.Format(CultureInfo.InvariantCulture, "default({0})", parameter.DeclarationExpression); + if (parameter.DefaultValue != null && parameter.Type is PrimaryType) + { + defaultValue = parameter.DefaultValue; + } + declarations.Add(string.Format(CultureInfo.InvariantCulture, + format, parameter.DeclarationExpression, parameter.Name, defaultValue)); } + if (addCustomHeaderParameters) { - declarations += "Dictionary> customHeaders = null"; + declarations.Add("Dictionary> customHeaders = null"); } - return declarations; + return string.Join(", ", declarations); } /// diff --git a/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml b/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml index 3a964744a4b46..09ba406f0844c 100644 --- a/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml +++ b/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml @@ -27,7 +27,7 @@ @:@WrapComment("/// ", parameter.Documentation.EscapeXmlComment()) @:/// } -@:public static @Model.ReturnTypeString @(Model.Name)(@Model.GetExtensionParameters(Model.SyncMethodParameterDeclaration)) +@:public static @Model.ReturnTypeString @(Model.Name)(@Model.GetExtensionParameters(Model.GetSyncMethodParameterDeclaration(false))) @:{ if (Model.ReturnType.Body != null) {