This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 361dd8b6f AVRO-3491 Avoid a cast after is check (#1645)
361dd8b6f is described below

commit 361dd8b6ffdcba93c34a1801445c15fa02447442
Author: Kyle Schoonover <[email protected]>
AuthorDate: Tue Apr 19 11:40:48 2022 -0700

    AVRO-3491 Avoid a cast after is check (#1645)
    
    * AVRO-3360 Updated XML documentation
    
    * Revert "AVRO-3360 Updated XML documentation"
    
    This reverts commit b8601c072a5083380d30b580804dd0908b8cf4cc.
    
    * AVRO-3491 Avoid a cast after is check
    
    Co-authored-by: Kyle T. Schoonover <[email protected]>
---
 lang/csharp/src/apache/main/Generic/GenericDatumReader.cs  | 14 +++++++-------
 .../src/apache/main/Generic/PreresolvingDatumReader.cs     | 11 +++++------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs 
b/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs
index 76a95b94e..1ec126b3a 100644
--- a/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs
+++ b/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs
@@ -98,16 +98,16 @@ namespace Avro.Generic
 
             public object CreateEnum(object reuse, int ordinal)
             {
-                if (reuse is GenericEnum)
+                if (reuse is GenericEnum ge)
                 {
-                    var ge = (GenericEnum) reuse;
-                    if (ge.Schema.Equals(this.schema))
+                    if (ge.Schema.Equals(schema))
                     {
-                        ge.Value = this.schema[ordinal];
+                        ge.Value = schema[ordinal];
                         return ge;
                     }
                 }
-                return new GenericEnum(this.schema, this.schema[ordinal]);
+
+                return new GenericEnum(schema, schema[ordinal]);
             }
         }
 
@@ -204,12 +204,12 @@ namespace Avro.Generic
         {
             public object Create(object reuse)
             {
-                if (reuse is IDictionary<string, object>)
+                if (reuse is IDictionary<string, object> result)
                 {
-                    var result = (IDictionary<string, object>)reuse;
                     result.Clear();
                     return result;
                 }
+
                 return new Dictionary<string, object>();
             }
 
diff --git a/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs 
b/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs
index 61273e85a..22c80407d 100644
--- a/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs
+++ b/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs
@@ -319,15 +319,14 @@ namespace Avro.Generic
 
             for (int i = 0; i < writerSchema.Count; i++)
             {
-                var writerBranch = writerSchema[i];
+                Schema writerBranch = writerSchema[i];
 
-                if (readerSchema is UnionSchema)
+                if (readerSchema is UnionSchema unionReader)
                 {
-                    var unionReader = (UnionSchema) readerSchema;
-                    var readerBranch = 
unionReader.MatchingBranch(writerBranch);
+                    int readerBranch = 
unionReader.MatchingBranch(writerBranch);
                     if (readerBranch == -1)
                     {
-                        lookup[i] = (r, d) => { throw new AvroException( "No 
matching schema for " + writerBranch + " in " + unionReader ); };
+                        lookup[i] = (r, d) => { throw new AvroException("No 
matching schema for " + writerBranch + " in " + unionReader); };
                     }
                     else
                     {
@@ -338,7 +337,7 @@ namespace Avro.Generic
                 {
                     if (!readerSchema.CanRead(writerBranch))
                     {
-                        lookup[i] = (r, d) => { throw new AvroException( 
"Schema mismatch Reader: " + ReaderSchema + ", writer: " + WriterSchema ); };
+                        lookup[i] = (r, d) => { throw new 
AvroException("Schema mismatch Reader: " + ReaderSchema + ", writer: " + 
WriterSchema); };
                     }
                     else
                     {

Reply via email to