Skip to content

Commit

Permalink
Addressed fxcop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stankovski committed May 27, 2016
1 parent e6f05e8 commit fbdcc27
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
5 changes: 3 additions & 2 deletions AutoRest/Generators/CSharp/CSharp/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.ClientModel.Constraint,System.String>,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")]
Expand All @@ -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<Microsoft.Rest.Generator.ClientModel.Constraint,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.#AppendConstraintValidations(System.String,System.Collections.Generic.Dictionary`2<Microsoft.Rest.Generator.ClientModel.Constraint,System.String>,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)")]

Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,8 @@ public string FailureStatusCodePredicate
}
return "!_httpResponse.IsSuccessStatusCode";
}
}

/// <summary>
/// Generate the method parameter declarations for the sync extension
/// </summary>
public string SyncMethodParameterDeclaration
{
get
{
List<string> declarations = new List<string>();
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);
}
}


}

/// <summary>
/// Generate the method parameter declaration for async methods and extensions
/// </summary>
Expand All @@ -101,18 +76,25 @@ public virtual string GetAsyncMethodParameterDeclaration()
/// <returns>Generated string of parameters</returns>
public virtual string GetSyncMethodParameterDeclaration(bool addCustomHeaderParameters)
{
var declarations = this.SyncMethodParameterDeclaration;

if (!string.IsNullOrEmpty(declarations) && addCustomHeaderParameters)
List<string> declarations = new List<string>();
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<string, List<string>> customHeaders = null";
declarations.Add("Dictionary<string, List<string>> customHeaders = null");
}

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

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@:@WrapComment("/// ", parameter.Documentation.EscapeXmlComment())
@:/// </param>
}
@: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)
{
Expand Down

0 comments on commit fbdcc27

Please sign in to comment.