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 2014d7d6f86ad0a48f801ef152dbc88ef208f620 Author: Brian Lachniet <[email protected]> AuthorDate: Sun Aug 18 21:00:26 2019 -0400 AVRO-2454: Fix CA1715 - Identifiers should have correct prefix --- lang/csharp/Avro.ruleset | 1 - lang/csharp/src/apache/main/Generic/DatumReader.cs | 2 ++ lang/csharp/src/apache/main/Generic/DatumWriter.cs | 2 ++ .../src/apache/main/Generic/GenericReader.cs | 4 ++-- .../src/apache/main/Generic/GenericWriter.cs | 8 +++---- .../apache/main/Generic/PreresolvingDatumWriter.cs | 8 +++---- lang/csharp/src/apache/main/IO/Decoder.cs | 2 ++ lang/csharp/src/apache/main/IO/Encoder.cs | 2 ++ lang/csharp/src/apache/main/Reflect/ClassCache.cs | 10 ++++---- .../src/apache/main/Reflect/FuncFieldConverter.cs | 16 ++++++------- .../src/apache/main/Reflect/TypedFieldConverter.cs | 27 +++++++++++----------- 11 files changed, 43 insertions(+), 39 deletions(-) diff --git a/lang/csharp/Avro.ruleset b/lang/csharp/Avro.ruleset index 00e630d..4900e32 100644 --- a/lang/csharp/Avro.ruleset +++ b/lang/csharp/Avro.ruleset @@ -27,7 +27,6 @@ <Rule Id="CA1062" Action="Info" /> <Rule Id="CA1707" Action="Info" /> <Rule Id="CA1710" Action="Info" /> - <Rule Id="CA1715" Action="Info" /> <Rule Id="CA1716" Action="Info" /> <Rule Id="CA1720" Action="Info" /> <Rule Id="CA1721" Action="Info" /> diff --git a/lang/csharp/src/apache/main/Generic/DatumReader.cs b/lang/csharp/src/apache/main/Generic/DatumReader.cs index e1f4213..a8a2bbc 100644 --- a/lang/csharp/src/apache/main/Generic/DatumReader.cs +++ b/lang/csharp/src/apache/main/Generic/DatumReader.cs @@ -23,6 +23,8 @@ namespace Avro.Generic /// Defines the interface for an object that reads data of a schema. /// </summary> /// <typeparam name="T">Type of the in-memory data representation.</typeparam> + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", + "CA1715:Identifiers should have correct prefix", Justification = "Maintain public API")] public interface DatumReader<T> { /// <summary> diff --git a/lang/csharp/src/apache/main/Generic/DatumWriter.cs b/lang/csharp/src/apache/main/Generic/DatumWriter.cs index dcf7993..be68365 100644 --- a/lang/csharp/src/apache/main/Generic/DatumWriter.cs +++ b/lang/csharp/src/apache/main/Generic/DatumWriter.cs @@ -23,6 +23,8 @@ namespace Avro.Generic /// Defines the interface for an object that writes data of a schema. /// </summary> /// <typeparam name="T">Type of the in-memory data representation.</typeparam> + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", + "CA1715:Identifiers should have correct prefix", Justification = "Maintain public API")] public interface DatumWriter<T> { /// <summary> diff --git a/lang/csharp/src/apache/main/Generic/GenericReader.cs b/lang/csharp/src/apache/main/Generic/GenericReader.cs index 9c1a25e..b6813fa 100644 --- a/lang/csharp/src/apache/main/Generic/GenericReader.cs +++ b/lang/csharp/src/apache/main/Generic/GenericReader.cs @@ -246,12 +246,12 @@ namespace Avro.Generic /// <summary> /// A generic function to read primitive types /// </summary> - /// <typeparam name="S">The .NET type to read</typeparam> + /// <typeparam name="T">The .NET type to read</typeparam> /// <param name="tag">The Avro type tag for the object on the stream</param> /// <param name="readerSchema">A schema compatible to the Avro type</param> /// <param name="reader">A function that can read the avro type from the stream</param> /// <returns>The primitive type just read</returns> - protected S Read<S>(Schema.Type tag, Schema readerSchema, Reader<S> reader) + protected T Read<T>(Schema.Type tag, Schema readerSchema, Reader<T> reader) { return reader(); } diff --git a/lang/csharp/src/apache/main/Generic/GenericWriter.cs b/lang/csharp/src/apache/main/Generic/GenericWriter.cs index f2fb24a..5f439bb 100644 --- a/lang/csharp/src/apache/main/Generic/GenericWriter.cs +++ b/lang/csharp/src/apache/main/Generic/GenericWriter.cs @@ -179,14 +179,14 @@ namespace Avro.Generic /// <summary> /// A generic method to serialize primitive Avro types. /// </summary> - /// <typeparam name="S">Type of the C# type to be serialized</typeparam> + /// <typeparam name="T">Type of the C# type to be serialized</typeparam> /// <param name="value">The value to be serialized</param> /// <param name="tag">The schema type tag</param> /// <param name="writer">The writer which should be used to write the given type.</param> - protected virtual void Write<S>(object value, Schema.Type tag, Writer<S> writer) + protected virtual void Write<T>(object value, Schema.Type tag, Writer<T> writer) { - if (!(value is S)) throw TypeMismatch(value, tag.ToString(), typeof(S).ToString()); - writer((S)value); + if (!(value is T)) throw TypeMismatch(value, tag.ToString(), typeof(T).ToString()); + writer((T)value); } /// <summary> diff --git a/lang/csharp/src/apache/main/Generic/PreresolvingDatumWriter.cs b/lang/csharp/src/apache/main/Generic/PreresolvingDatumWriter.cs index 7b52721..e4e96d3 100644 --- a/lang/csharp/src/apache/main/Generic/PreresolvingDatumWriter.cs +++ b/lang/csharp/src/apache/main/Generic/PreresolvingDatumWriter.cs @@ -117,14 +117,14 @@ namespace Avro.Generic /// <summary> /// A generic method to serialize primitive Avro types. /// </summary> - /// <typeparam name="S">Type of the C# type to be serialized</typeparam> + /// <typeparam name="TValue">Type of the C# type to be serialized</typeparam> /// <param name="value">The value to be serialized</param> /// <param name="tag">The schema type tag</param> /// <param name="writer">The writer which should be used to write the given type.</param> - protected void Write<S>(object value, Schema.Type tag, Writer<S> writer) + protected void Write<TValue>(object value, Schema.Type tag, Writer<TValue> writer) { - if (!(value is S)) throw TypeMismatch(value, tag.ToString(), typeof(S).ToString()); - writer((S)value); + if (!(value is TValue)) throw TypeMismatch(value, tag.ToString(), typeof(TValue).ToString()); + writer((TValue)value); } diff --git a/lang/csharp/src/apache/main/IO/Decoder.cs b/lang/csharp/src/apache/main/IO/Decoder.cs index 573a8dd..536c1e9 100644 --- a/lang/csharp/src/apache/main/IO/Decoder.cs +++ b/lang/csharp/src/apache/main/IO/Decoder.cs @@ -22,6 +22,8 @@ namespace Avro.IO /// Decoder is used to decode Avro data on a stream. There are methods to read the Avro types on the stream. There are also /// methods to skip items, which are usually more efficient than reading, on the stream. /// </summary> + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", + "CA1715:Identifiers should have correct prefix", Justification = "Maintain public API")] public interface Decoder { /// <summary> diff --git a/lang/csharp/src/apache/main/IO/Encoder.cs b/lang/csharp/src/apache/main/IO/Encoder.cs index e04f3eb..24d7381 100644 --- a/lang/csharp/src/apache/main/IO/Encoder.cs +++ b/lang/csharp/src/apache/main/IO/Encoder.cs @@ -22,6 +22,8 @@ namespace Avro.IO /// Defines the interface for a class that provies low-level support for serializing Avro /// values. /// </summary> + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", + "CA1715:Identifiers should have correct prefix", Justification = "Maintain public API")] public interface Encoder { /// <summary> diff --git a/lang/csharp/src/apache/main/Reflect/ClassCache.cs b/lang/csharp/src/apache/main/Reflect/ClassCache.cs index 22b56c4..27ac8de 100644 --- a/lang/csharp/src/apache/main/Reflect/ClassCache.cs +++ b/lang/csharp/src/apache/main/Reflect/ClassCache.cs @@ -19,8 +19,6 @@ using System; using System.Collections; using System.Collections.Concurrent; -using System.Reflection; -using Avro; namespace Avro.Reflect { @@ -65,11 +63,11 @@ namespace Avro.Reflect /// </summary> /// <param name="from"></param> /// <param name="to"></param> - /// <typeparam name="A"></typeparam> - /// <typeparam name="P"></typeparam> - public static void AddDefaultConverter<A, P>(Func<A, Schema, P> from, Func<P, Schema, A> to) + /// <typeparam name="TAvro"></typeparam> + /// <typeparam name="TProperty"></typeparam> + public static void AddDefaultConverter<TAvro, TProperty>(Func<TAvro, Schema, TProperty> from, Func<TProperty, Schema, TAvro> to) { - _defaultConverters.Add(new FuncFieldConverter<A, P>(from, to)); + _defaultConverters.Add(new FuncFieldConverter<TAvro, TProperty>(from, to)); } /// <summary> diff --git a/lang/csharp/src/apache/main/Reflect/FuncFieldConverter.cs b/lang/csharp/src/apache/main/Reflect/FuncFieldConverter.cs index 0cc0bbe..889ddbf 100644 --- a/lang/csharp/src/apache/main/Reflect/FuncFieldConverter.cs +++ b/lang/csharp/src/apache/main/Reflect/FuncFieldConverter.cs @@ -23,24 +23,24 @@ namespace Avro.Reflect /// <summary> /// Field converter using a Func /// </summary> - /// <typeparam name="A">Avro type</typeparam> - /// <typeparam name="P">Property type</typeparam> - public class FuncFieldConverter<A, P> : TypedFieldConverter<A, P> + /// <typeparam name="TAvro">Avro type</typeparam> + /// <typeparam name="TProperty">Property type</typeparam> + public class FuncFieldConverter<TAvro, TProperty> : TypedFieldConverter<TAvro, TProperty> { /// <summary> /// Initializes a new instance of the <see cref="FuncFieldConverter{A, P}"/> class. /// </summary> /// <param name="from">Delegate to convert from C# type to Avro type</param> /// <param name="to">Delegate to convert from Avro type to C# type</param> - public FuncFieldConverter(Func<A, Schema, P> from, Func<P, Schema, A> to) + public FuncFieldConverter(Func<TAvro, Schema, TProperty> from, Func<TProperty, Schema, TAvro> to) { _from = from; _to = to; } - private Func<A, Schema, P> _from; + private Func<TAvro, Schema, TProperty> _from; - private Func<P, Schema, A> _to; + private Func<TProperty, Schema, TAvro> _to; /// <summary> /// Inherited conversion method - call the Func. @@ -48,7 +48,7 @@ namespace Avro.Reflect /// <param name="o"></param> /// <param name="s"></param> /// <returns></returns> - public override P From(A o, Schema s) + public override TProperty From(TAvro o, Schema s) { return _from(o, s); } @@ -59,7 +59,7 @@ namespace Avro.Reflect /// <param name="o"></param> /// <param name="s"></param> /// <returns></returns> - public override A To(P o, Schema s) + public override TAvro To(TProperty o, Schema s) { return _to(o, s); } diff --git a/lang/csharp/src/apache/main/Reflect/TypedFieldConverter.cs b/lang/csharp/src/apache/main/Reflect/TypedFieldConverter.cs index bd0a0ec..8b3687b 100644 --- a/lang/csharp/src/apache/main/Reflect/TypedFieldConverter.cs +++ b/lang/csharp/src/apache/main/Reflect/TypedFieldConverter.cs @@ -17,16 +17,15 @@ */ using System; -using System.Reflection; namespace Avro.Reflect { /// <summary> /// Constructor /// </summary> - /// <typeparam name="A">Avro type</typeparam> - /// <typeparam name="P">Property type</typeparam> - public abstract class TypedFieldConverter<A, P> : IAvroFieldConverter + /// <typeparam name="TAvro">Avro type</typeparam> + /// <typeparam name="TProperty">Property type</typeparam> + public abstract class TypedFieldConverter<TAvro, TProperty> : IAvroFieldConverter { /// <summary> /// Convert from Avro type to property type @@ -34,7 +33,7 @@ namespace Avro.Reflect /// <param name="o">Avro value</param> /// <param name="s">Schema</param> /// <returns>Property value</returns> - public abstract P From(A o, Schema s); + public abstract TProperty From(TAvro o, Schema s); /// <summary> /// Convert from property type to Avro type @@ -42,7 +41,7 @@ namespace Avro.Reflect /// <param name="o"></param> /// <param name="s"></param> /// <returns></returns> - public abstract A To(P o, Schema s); + public abstract TAvro To(TProperty o, Schema s); /// <summary> /// Implement untyped interface @@ -52,12 +51,12 @@ namespace Avro.Reflect /// <returns></returns> public object FromAvroType(object o, Schema s) { - if (!typeof(A).IsAssignableFrom(o.GetType())) + if (!typeof(TAvro).IsAssignableFrom(o.GetType())) { - throw new AvroException($"Converter from {typeof(A).Name} to {typeof(P).Name} cannot convert object of type {o.GetType().Name} to {typeof(A).Name}, object {o.ToString()}"); + throw new AvroException($"Converter from {typeof(TAvro).Name} to {typeof(TProperty).Name} cannot convert object of type {o.GetType().Name} to {typeof(TAvro).Name}, object {o.ToString()}"); } - return From((A)o, s); + return From((TAvro)o, s); } /// <summary> @@ -66,7 +65,7 @@ namespace Avro.Reflect /// <returns></returns> public Type GetAvroType() { - return typeof(A); + return typeof(TAvro); } /// <summary> @@ -75,7 +74,7 @@ namespace Avro.Reflect /// <returns></returns> public Type GetPropertyType() { - return typeof(P); + return typeof(TProperty); } /// <summary> @@ -86,12 +85,12 @@ namespace Avro.Reflect /// <returns></returns> public object ToAvroType(object o, Schema s) { - if (!typeof(P).IsAssignableFrom(o.GetType())) + if (!typeof(TProperty).IsAssignableFrom(o.GetType())) { - throw new AvroException($"Converter from {typeof(A).Name} to {typeof(P).Name} cannot convert object of type {o.GetType().Name} to {typeof(P).Name}, object {o.ToString()}"); + throw new AvroException($"Converter from {typeof(TAvro).Name} to {typeof(TProperty).Name} cannot convert object of type {o.GetType().Name} to {typeof(TProperty).Name}, object {o.ToString()}"); } - return To((P)o, s); + return To((TProperty)o, s); } } }
