You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by bl...@apache.org on 2019/09/04 00:22:43 UTC
[avro] 10/17: AVRO-2454: Fix CA1507 - Use nameof in place of string
This is an automated email from the ASF dual-hosted git repository.
blachniet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
commit 0e1073e98b4323fd85af1826a72ca12d5eabc1d2
Author: Brian Lachniet <bl...@gmail.com>
AuthorDate: Sun Aug 18 14:27:29 2019 -0400
AVRO-2454: Fix CA1507 - Use nameof in place of string
---
lang/csharp/Avro.ruleset | 1 -
lang/csharp/src/apache/main/CodeGen/CodeGen.cs | 2 +-
lang/csharp/src/apache/main/Protocol/Message.cs | 2 +-
lang/csharp/src/apache/main/Protocol/Protocol.cs | 6 +++---
lang/csharp/src/apache/main/Schema/ArraySchema.cs | 2 +-
lang/csharp/src/apache/main/Schema/Field.cs | 2 +-
lang/csharp/src/apache/main/Schema/FixedSchema.cs | 2 +-
lang/csharp/src/apache/main/Schema/JsonHelper.cs | 8 ++++----
lang/csharp/src/apache/main/Schema/MapSchema.cs | 2 +-
lang/csharp/src/apache/main/Schema/RecordSchema.cs | 2 +-
lang/csharp/src/apache/main/Schema/Schema.cs | 2 +-
lang/csharp/src/apache/main/Schema/UnionSchema.cs | 2 +-
12 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/lang/csharp/Avro.ruleset b/lang/csharp/Avro.ruleset
index 1f12d7f..0931157 100644
--- a/lang/csharp/Avro.ruleset
+++ b/lang/csharp/Avro.ruleset
@@ -25,7 +25,6 @@
We disabled these rules initially to get the code analyzers installed in the project.
-->
<Rule Id="CA1062" Action="Info" />
- <Rule Id="CA1507" Action="Info" />
<Rule Id="CA1707" Action="Info" />
<Rule Id="CA1710" Action="Info" />
<Rule Id="CA1715" Action="Info" />
diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
index be33321..40c7256 100644
--- a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
+++ b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
@@ -105,7 +105,7 @@ namespace Avro
protected virtual CodeNamespace addNamespace(string name)
{
if (string.IsNullOrEmpty(name))
- throw new ArgumentNullException("name", "name cannot be null.");
+ throw new ArgumentNullException(nameof(name), "name cannot be null.");
CodeNamespace ns = null;
diff --git a/lang/csharp/src/apache/main/Protocol/Message.cs b/lang/csharp/src/apache/main/Protocol/Message.cs
index 34edd0a..5e455ef 100644
--- a/lang/csharp/src/apache/main/Protocol/Message.cs
+++ b/lang/csharp/src/apache/main/Protocol/Message.cs
@@ -75,7 +75,7 @@ namespace Avro
/// </param>
public Message(string name, string doc, RecordSchema request, Schema response, UnionSchema error, bool? oneway)
{
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "name cannot be null.");
+ if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name), "name cannot be null.");
this.Request = request;
this.Response = response;
this.Error = error;
diff --git a/lang/csharp/src/apache/main/Protocol/Protocol.cs b/lang/csharp/src/apache/main/Protocol/Protocol.cs
index 2665823..cd4e0cc 100644
--- a/lang/csharp/src/apache/main/Protocol/Protocol.cs
+++ b/lang/csharp/src/apache/main/Protocol/Protocol.cs
@@ -86,9 +86,9 @@ namespace Avro
string doc, IEnumerable<Schema> types,
IDictionary<string,Message> messages)
{
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "name cannot be null.");
- if (null == types) throw new ArgumentNullException("types", "types cannot be null.");
- if (null == messages) throw new ArgumentNullException("messages", "messages cannot be null.");
+ if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name), "name cannot be null.");
+ if (null == types) throw new ArgumentNullException(nameof(types), "types cannot be null.");
+ if (null == messages) throw new ArgumentNullException(nameof(messages), "messages cannot be null.");
this.Name = name;
this.Namespace = space;
diff --git a/lang/csharp/src/apache/main/Schema/ArraySchema.cs b/lang/csharp/src/apache/main/Schema/ArraySchema.cs
index 0976ed7..5b4e6a4 100644
--- a/lang/csharp/src/apache/main/Schema/ArraySchema.cs
+++ b/lang/csharp/src/apache/main/Schema/ArraySchema.cs
@@ -54,7 +54,7 @@ namespace Avro
/// <param name="props">dictionary that provides access to custom properties</param>
private ArraySchema(Schema items, PropertyMap props) : base(Type.Array, props)
{
- if (null == items) throw new ArgumentNullException("items");
+ if (null == items) throw new ArgumentNullException(nameof(items));
this.ItemSchema = items;
}
diff --git a/lang/csharp/src/apache/main/Schema/Field.cs b/lang/csharp/src/apache/main/Schema/Field.cs
index 1d5bedb..026b5b2 100644
--- a/lang/csharp/src/apache/main/Schema/Field.cs
+++ b/lang/csharp/src/apache/main/Schema/Field.cs
@@ -124,7 +124,7 @@ namespace Avro
internal Field(Schema schema, string name, IList<string> aliases, int pos, string doc,
JToken defaultValue, SortOrder sortorder, PropertyMap props)
{
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "name cannot be null.");
+ if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name), "name cannot be null.");
if (null == schema) throw new ArgumentNullException("type", "type cannot be null.");
this.Schema = schema;
this.Name = name;
diff --git a/lang/csharp/src/apache/main/Schema/FixedSchema.cs b/lang/csharp/src/apache/main/Schema/FixedSchema.cs
index 098e32c..b16c1ff 100644
--- a/lang/csharp/src/apache/main/Schema/FixedSchema.cs
+++ b/lang/csharp/src/apache/main/Schema/FixedSchema.cs
@@ -69,7 +69,7 @@ namespace Avro
: base(Type.Fixed, name, aliases, props, names, doc)
{
if (null == name.Name) throw new SchemaParseException("name cannot be null for fixed schema.");
- if (size <= 0) throw new ArgumentOutOfRangeException("size", "size must be greater than zero.");
+ if (size <= 0) throw new ArgumentOutOfRangeException(nameof(size), "size must be greater than zero.");
this.Size = size;
}
diff --git a/lang/csharp/src/apache/main/Schema/JsonHelper.cs b/lang/csharp/src/apache/main/Schema/JsonHelper.cs
index 7cbea49..87887f5 100644
--- a/lang/csharp/src/apache/main/Schema/JsonHelper.cs
+++ b/lang/csharp/src/apache/main/Schema/JsonHelper.cs
@@ -34,8 +34,8 @@ namespace Avro
/// <returns>property value if property exists, null if property doesn't exist in the JSON object</returns>
public static string GetOptionalString(JToken jtok, string field)
{
- if (null == jtok) throw new ArgumentNullException("jtok", "jtok cannot be null.");
- if (string.IsNullOrEmpty(field)) throw new ArgumentNullException("field", $"field cannot be null at '{jtok.Path}'");
+ if (null == jtok) throw new ArgumentNullException(nameof(jtok), "jtok cannot be null.");
+ if (string.IsNullOrEmpty(field)) throw new ArgumentNullException(nameof(field), $"field cannot be null at '{jtok.Path}'");
JToken child = jtok[field];
if (null == child) return null;
@@ -85,8 +85,8 @@ namespace Avro
/// <returns>null if property doesn't exist, otherise returns property boolean value</returns>
public static bool? GetOptionalBoolean(JToken jtok, string field)
{
- if (null == jtok) throw new ArgumentNullException("jtok", "jtok cannot be null.");
- if (string.IsNullOrEmpty(field)) throw new ArgumentNullException("field", $"field cannot be null at '{jtok.Path}'");
+ if (null == jtok) throw new ArgumentNullException(nameof(jtok), "jtok cannot be null.");
+ if (string.IsNullOrEmpty(field)) throw new ArgumentNullException(nameof(field), $"field cannot be null at '{jtok.Path}'");
JToken child = jtok[field];
if (null == child) return null;
diff --git a/lang/csharp/src/apache/main/Schema/MapSchema.cs b/lang/csharp/src/apache/main/Schema/MapSchema.cs
index e50b04e..54bc05a 100644
--- a/lang/csharp/src/apache/main/Schema/MapSchema.cs
+++ b/lang/csharp/src/apache/main/Schema/MapSchema.cs
@@ -71,7 +71,7 @@ namespace Avro
/// <param name="props">dictionary that provides access to custom properties</param>
private MapSchema(Schema valueSchema, PropertyMap props) : base(Type.Map, props)
{
- if (null == valueSchema) throw new ArgumentNullException("valueSchema", "valueSchema cannot be null.");
+ if (null == valueSchema) throw new ArgumentNullException(nameof(valueSchema), "valueSchema cannot be null.");
this.ValueSchema = valueSchema;
}
diff --git a/lang/csharp/src/apache/main/Schema/RecordSchema.cs b/lang/csharp/src/apache/main/Schema/RecordSchema.cs
index c485f5d..6f01d0c 100644
--- a/lang/csharp/src/apache/main/Schema/RecordSchema.cs
+++ b/lang/csharp/src/apache/main/Schema/RecordSchema.cs
@@ -178,7 +178,7 @@ namespace Avro
{
get
{
- if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
+ if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));
Field field;
return fieldLookup.TryGetValue(name, out field) ? field : null;
}
diff --git a/lang/csharp/src/apache/main/Schema/Schema.cs b/lang/csharp/src/apache/main/Schema/Schema.cs
index 046151d..aba4e72 100644
--- a/lang/csharp/src/apache/main/Schema/Schema.cs
+++ b/lang/csharp/src/apache/main/Schema/Schema.cs
@@ -206,7 +206,7 @@ namespace Avro
/// <returns>new Schema object</returns>
public static Schema Parse(string json)
{
- if (string.IsNullOrEmpty(json)) throw new ArgumentNullException("json", "json cannot be null.");
+ if (string.IsNullOrEmpty(json)) throw new ArgumentNullException(nameof(json), "json cannot be null.");
return Parse(json.Trim(), new SchemaNames(), null); // standalone schema, so no enclosing namespace
}
diff --git a/lang/csharp/src/apache/main/Schema/UnionSchema.cs b/lang/csharp/src/apache/main/Schema/UnionSchema.cs
index e3a0fe1..0ffb5e0 100644
--- a/lang/csharp/src/apache/main/Schema/UnionSchema.cs
+++ b/lang/csharp/src/apache/main/Schema/UnionSchema.cs
@@ -75,7 +75,7 @@ namespace Avro
private UnionSchema(List<Schema> schemas, PropertyMap props) : base(Type.Union, props)
{
if (schemas == null)
- throw new ArgumentNullException("schemas");
+ throw new ArgumentNullException(nameof(schemas));
this.Schemas = schemas;
}