diff --git a/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs b/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs index 76a95b94ead..1ec126b3aa4 100644 --- a/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs +++ b/lang/csharp/src/apache/main/Generic/GenericDatumReader.cs @@ -98,16 +98,16 @@ public GenericEnumAccess(EnumSchema schema) 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 @@ class GenericMapAccess : MapAccess { public object Create(object reuse) { - if (reuse is IDictionary) + if (reuse is IDictionary result) { - var result = (IDictionary)reuse; result.Clear(); return result; } + return new Dictionary(); } diff --git a/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs b/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs index 61273e85a49..22c80407dde 100644 --- a/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs +++ b/lang/csharp/src/apache/main/Generic/PreresolvingDatumReader.cs @@ -319,15 +319,14 @@ private ReadItem ResolveUnion(UnionSchema writerSchema, Schema readerSchema) 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 @@ private ReadItem ResolveUnion(UnionSchema writerSchema, Schema readerSchema) { 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 {