avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blachn...@apache.org
Subject [avro] branch branch-1.9 updated: AVRO-2454: Add FxCop and StyleCop to C# bindings (#609)
Date Sat, 17 Aug 2019 11:58:24 GMT
This is an automated email from the ASF dual-hosted git repository.

blachniet pushed a commit to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.9 by this push:
     new a104c5d  AVRO-2454: Add FxCop and StyleCop to C# bindings (#609)
a104c5d is described below

commit a104c5d6e209b11d98d3f261139153a2311887af
Author: Brian Lachniet <blachniet@gmail.com>
AuthorDate: Sat Aug 17 07:53:53 2019 -0400

    AVRO-2454: Add FxCop and StyleCop to C# bindings (#609)
    
    * Add Microsoft.CodeAnalysis.FxCopAnalyzers
    * Fix CA1000 - Do not declare static members on generic types
    * Fix CA1032 - Implement standard exception constructors
    * Fix CA1065 - Do not raise exceptions in unexpected locations
    * Fix CA1304 - Specify CultureInfo
    * Fix CA1308 - Normalize strings to uppercase
    * Add a CodeAnalysis ruleset
    * Add StyleCop.Anlayzers
    * Fix CA1031 - Do not catch general exception types
    * Fix CA1051 - Do not declare visible instance fields
    
    (cherry picked from commit 93a3ca4f6a3ace56a2e32d4249d05dad6f220f1f)
---
 lang/csharp/Avro.ruleset                           | 153 +++++++++++++++++++++
 lang/csharp/Avro.sln                               |   2 +
 lang/csharp/src/apache/main/Avro.main.csproj       |  13 ++
 .../apache/main/CodeGen/AvroRuntimeException.cs    |   7 +
 lang/csharp/src/apache/main/CodeGen/CodeGen.cs     |  16 ++-
 .../src/apache/main/CodeGen/CodeGenException.cs    |  10 +-
 lang/csharp/src/apache/main/File/DataFileReader.cs |  17 ++-
 lang/csharp/src/apache/main/GlobalSuppressions.cs  |  42 ++++++
 .../apache/main/Protocol/ProtocolParseException.cs |   7 +
 .../csharp/src/apache/main/Schema/AvroException.cs |   7 +
 .../src/apache/main/Schema/AvroTypeException.cs    |  24 ++++
 lang/csharp/src/apache/main/Schema/Field.cs        |  17 ++-
 lang/csharp/src/apache/main/Schema/RecordSchema.cs |   8 +-
 lang/csharp/src/apache/main/Schema/Schema.cs       |   5 +-
 .../src/apache/main/Schema/SchemaParseException.cs |  24 +++-
 .../src/apache/main/Specific/ObjectCreator.cs      |   4 +-
 .../src/apache/main/Specific/SpecificException.cs  |  31 +++++
 lang/csharp/stylecop.json                          |  26 ++++
 18 files changed, 385 insertions(+), 28 deletions(-)

diff --git a/lang/csharp/Avro.ruleset b/lang/csharp/Avro.ruleset
new file mode 100644
index 0000000..e5a3983
--- /dev/null
+++ b/lang/csharp/Avro.ruleset
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       https://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<RuleSet Name="New Rule Set" Description=" " ToolsVersion="16.0">
+  <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
+    <!--
+    AVRO-2454: We need to evaluate each of these rules to determine whether we should enforce
them.
+    We disabled these rules initially to get the code analyzers installed in the project.
+    -->
+    <Rule Id="CA1034" Action="Info" />
+    <Rule Id="CA1052" Action="Info" />
+    <Rule Id="CA1062" Action="Info" />
+    <Rule Id="CA1063" Action="Info" />
+    <Rule Id="CA1303" Action="Info" />
+    <Rule Id="CA1305" Action="Info" />
+    <Rule Id="CA1307" Action="Info" />
+    <Rule Id="CA1507" 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" />
+    <Rule Id="CA1724" Action="Info" />
+    <Rule Id="CA1801" Action="Info" />
+    <Rule Id="CA1816" Action="Info" />
+    <Rule Id="CA1819" Action="Info" />
+    <Rule Id="CA1820" Action="Info" />
+    <Rule Id="CA1822" Action="Info" />
+    <Rule Id="CA1825" Action="Info" />
+    <Rule Id="CA2000" Action="Info" />
+    <Rule Id="CA2008" Action="Info" />
+    <Rule Id="CA2208" Action="Info" />
+    <Rule Id="CA2211" Action="Info" />
+    <Rule Id="CA2213" Action="Info" />
+    <Rule Id="CA2227" Action="Info" />
+    <Rule Id="CA5351" Action="Info" />
+  </Rules>
+  <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
+    <!-- PrefixLocalCallsWithThis -->
+    <Rule Id="SA1101" Action="None" />
+
+    <!--
+    Element Ordering Rules
+    https://google.github.io/styleguide/javaguide.html#s3.4.2-ordering-class-contents
+    -->
+    <Rule Id="SA1201" Action="None" />
+    <Rule Id="SA1202" Action="None" />
+    <Rule Id="SA1203" Action="None" />
+    <Rule Id="SA1204" Action="None" />
+    <Rule Id="SA1214" Action="None" />
+    <Rule Id="SA1215" Action="None" />
+
+    <!--
+    FileMustHaveHeader: StyleCop does not recognize our headers. We're relying on RAT to
enforce
+    file headers.
+    -->
+    <Rule Id="SA1633" Action="None" />
+
+    <!--
+    AVRO-2454: We need to evaluate each of these rules to determine whether we should enforce
them.
+    We disabled these rules initially to get the code analyzers installed in the project.
+    -->
+    <Rule Id="SA1000" Action="Info" />
+    <Rule Id="SA1001" Action="Info" />
+    <Rule Id="SA1003" Action="Info" />
+    <Rule Id="SA1004" Action="Info" />
+    <Rule Id="SA1005" Action="Info" />
+    <Rule Id="SA1006" Action="Info" />
+    <Rule Id="SA1007" Action="Info" />
+    <Rule Id="SA1008" Action="Info" />
+    <Rule Id="SA1009" Action="Info" />
+    <Rule Id="SA1012" Action="Info" />
+    <Rule Id="SA1013" Action="Info" />
+    <Rule Id="SA1025" Action="Info" />
+    <Rule Id="SA1027" Action="Info" />
+    <Rule Id="SA1028" Action="Info" />
+    <Rule Id="SA1106" Action="Info" />
+    <Rule Id="SA1107" Action="Info" />
+    <Rule Id="SA1108" Action="Info" />
+    <Rule Id="SA1116" Action="Info" />
+    <Rule Id="SA1117" Action="Info" />
+    <Rule Id="SA1119" Action="Info" />
+    <Rule Id="SA1121" Action="Info" />
+    <Rule Id="SA1122" Action="Info" />
+    <Rule Id="SA1128" Action="Info" />
+    <Rule Id="SA1131" Action="Info" />
+    <Rule Id="SA1132" Action="Info" />
+    <Rule Id="SA1137" Action="Info" />
+    <Rule Id="SA1206" Action="Info" />
+    <Rule Id="SA1208" Action="Info" />
+    <Rule Id="SA1210" Action="Info" />
+    <Rule Id="SA1300" Action="Info" />
+    <Rule Id="SA1302" Action="Info" />
+    <Rule Id="SA1306" Action="Info" />
+    <Rule Id="SA1307" Action="Info" />
+    <Rule Id="SA1309" Action="Info" />
+    <Rule Id="SA1310" Action="Info" />
+    <Rule Id="SA1311" Action="Info" />
+    <Rule Id="SA1312" Action="Info" />
+    <Rule Id="SA1314" Action="Info" />
+    <Rule Id="SA1400" Action="Info" />
+    <Rule Id="SA1401" Action="Info" />
+    <Rule Id="SA1402" Action="Info" />
+    <Rule Id="SA1407" Action="Info" />
+    <Rule Id="SA1413" Action="Info" />
+    <Rule Id="SA1500" Action="Info" />
+    <Rule Id="SA1501" Action="Info" />
+    <Rule Id="SA1502" Action="Info" />
+    <Rule Id="SA1503" Action="Info" />
+    <Rule Id="SA1504" Action="Info" />
+    <Rule Id="SA1505" Action="Info" />
+    <Rule Id="SA1506" Action="Info" />
+    <Rule Id="SA1507" Action="Info" />
+    <Rule Id="SA1508" Action="Info" />
+    <Rule Id="SA1510" Action="Info" />
+    <Rule Id="SA1512" Action="Info" />
+    <Rule Id="SA1513" Action="Info" />
+    <Rule Id="SA1514" Action="Info" />
+    <Rule Id="SA1515" Action="Info" />
+    <Rule Id="SA1516" Action="Info" />
+    <Rule Id="SA1519" Action="Info" />
+    <Rule Id="SA1520" Action="Info" />
+    <Rule Id="SA1600" Action="Info" />
+    <Rule Id="SA1604" Action="Info" />
+    <Rule Id="SA1606" Action="Info" />
+    <Rule Id="SA1610" Action="Info" />
+    <Rule Id="SA1611" Action="Info" />
+    <Rule Id="SA1614" Action="Info" />
+    <Rule Id="SA1615" Action="Info" />
+    <Rule Id="SA1616" Action="Info" />
+    <Rule Id="SA1618" Action="Info" />
+    <Rule Id="SA1622" Action="Info" />
+    <Rule Id="SA1623" Action="Info" />
+    <Rule Id="SA1629" Action="Info" />
+    <Rule Id="SA1642" Action="Info" />
+    <Rule Id="SA1649" Action="Info" />
+  </Rules>
+</RuleSet>
diff --git a/lang/csharp/Avro.sln b/lang/csharp/Avro.sln
index c484f6e..68036eb 100644
--- a/lang/csharp/Avro.sln
+++ b/lang/csharp/Avro.sln
@@ -17,10 +17,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items",
"Solution
 	ProjectSection(SolutionItems) = preProject
 		..\..\.editorconfig = ..\..\.editorconfig
 		.gitignore = .gitignore
+		Avro.ruleset = Avro.ruleset
 		build.ps1 = build.ps1
 		build.sh = build.sh
 		common.props = common.props
 		README.md = README.md
+		stylecop.json = stylecop.json
 	EndProjectSection
 EndProject
 Global
diff --git a/lang/csharp/src/apache/main/Avro.main.csproj b/lang/csharp/src/apache/main/Avro.main.csproj
index 2dd06eb..d8d03e7 100644
--- a/lang/csharp/src/apache/main/Avro.main.csproj
+++ b/lang/csharp/src/apache/main/Avro.main.csproj
@@ -25,6 +25,7 @@
     <SignAssembly>true</SignAssembly>
     <AssemblyOriginatorKeyFile>..\..\..\Avro.snk</AssemblyOriginatorKeyFile>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
+    <CodeAnalysisRuleSet>..\..\..\Avro.ruleset</CodeAnalysisRuleSet>
   </PropertyGroup>
 
   <PropertyGroup>
@@ -47,7 +48,19 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <AdditionalFiles Include="..\..\..\stylecop.json" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
     <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
+    <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
     <PackageReference Include="System.CodeDom" Version="4.4.0" />
     <PackageReference Include="System.Reflection" Version="4.3.0" />
     <PackageReference Include="System.Reflection.Emit.ILGeneration" Version="4.3.0" />
diff --git a/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs b/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
index 807597c..7c8154a 100644
--- a/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
+++ b/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
@@ -27,6 +27,13 @@ namespace Avro
         /// <summary>
         /// Initializes a new instance of the <see cref="AvroRuntimeException"/> class.
         /// </summary>
+        public AvroRuntimeException()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="AvroRuntimeException"/> class.
+        /// </summary>
         /// <param name="s">The message that describes the error.</param>
         public AvroRuntimeException(string s)
             : base(s)
diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
index 29d7c4d..c3d1ef3 100644
--- a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
+++ b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
@@ -55,9 +55,21 @@ namespace Avro
         /// <summary>
         /// List of generated namespaces
         /// </summary>
+        [Obsolete("Use NamespaceLookup instead. This will be removed from the public API
in a future version.")]
         protected Dictionary<string, CodeNamespace> namespaceLookup = new Dictionary<string,
CodeNamespace>(StringComparer.Ordinal);
 
         /// <summary>
+        /// List of generated namespaces.
+        /// </summary>
+        protected Dictionary<string, CodeNamespace> NamespaceLookup
+        {
+#pragma warning disable CS0618 // Type or member is obsolete
+            get => namespaceLookup;
+            set => namespaceLookup = value;
+#pragma warning restore CS0618 // Type or member is obsolete
+        }
+
+        /// <summary>
         /// Default constructor
         /// </summary>
         public CodeGen()
@@ -97,7 +109,7 @@ namespace Avro
 
             CodeNamespace ns = null;
 
-            if (!namespaceLookup.TryGetValue(name, out ns))
+            if (!NamespaceLookup.TryGetValue(name, out ns))
             {
                 string csharpNamespace;
                 ns = NamespaceMapping.TryGetValue(name, out csharpNamespace)
@@ -108,7 +120,7 @@ namespace Avro
                     ns.Imports.Add(nci);
 
                 CompileUnit.Namespaces.Add(ns);
-                namespaceLookup.Add(name, ns);
+                NamespaceLookup.Add(name, ns);
             }
             return ns;
         }
diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs b/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
index ae2ac61..485646f 100644
--- a/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
+++ b/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
@@ -16,23 +16,23 @@
  * limitations under the License.
  */
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 
 namespace Avro
 {
     class CodeGenException : AvroException
     {
+        public CodeGenException()
+        {
+        }
+
         public CodeGenException(string s)
             : base(s)
         {
-
         }
+
         public CodeGenException(string s, Exception inner)
             : base(s, inner)
         {
-
         }
     }
 }
diff --git a/lang/csharp/src/apache/main/File/DataFileReader.cs b/lang/csharp/src/apache/main/File/DataFileReader.cs
index 6e61d39..61156fc 100644
--- a/lang/csharp/src/apache/main/File/DataFileReader.cs
+++ b/lang/csharp/src/apache/main/File/DataFileReader.cs
@@ -211,16 +211,25 @@ namespace Avro.File
             {
                 bool done = false;
 
-                do // read until sync mark matched
+                // read until sync mark matched
+                do
                 {
                     _decoder.ReadFixed(_syncBuffer);
                     if (Enumerable.SequenceEqual(_syncBuffer, _header.SyncData))
+                    {
                         done = true;
+                    }
                     else
-                        _stream.Position = _stream.Position - (DataFileConstants.SyncSize
- 1);
-                } while (!done);
+                    {
+                        _stream.Position -= DataFileConstants.SyncSize - 1;
+                    }
+                }
+                while (!done);
+            }
+            catch
+            {
+                // could not find .. default to EOF
             }
-            catch (Exception) { } // could not find .. default to EOF
 
             _blockStart = _stream.Position;
         }
diff --git a/lang/csharp/src/apache/main/GlobalSuppressions.cs b/lang/csharp/src/apache/main/GlobalSuppressions.cs
new file mode 100644
index 0000000..c73afa0
--- /dev/null
+++ b/lang/csharp/src/apache/main/GlobalSuppressions.cs
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileReader`1.OpenReader(System.IO.Stream)~Avro.File.IFileReader{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileReader`1.OpenReader(System.IO.Stream,Avro.Schema)~Avro.File.IFileReader{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileReader`1.OpenReader(System.IO.Stream,Avro.Schema,Avro.File.DataFileReader`1.CreateDatumReader`0)~Avro.File.IFileReader{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileReader`1.OpenReader(System.String)~Avro.File.IFileReader{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileReader`1.OpenReader(System.String,Avro.Schema)~Avro.File.IFileReader{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileWriter`1.OpenWriter(Avro.Generic.DatumWriter{`0},System.IO.Stream)~Avro.File.IFileWriter{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileWriter`1.OpenWriter(Avro.Generic.DatumWriter{`0},System.IO.Stream,Avro.File.Codec)~Avro.File.IFileWriter{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileWriter`1.OpenWriter(Avro.Generic.DatumWriter{`0},System.String)~Avro.File.IFileWriter{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare
static members on generic types", Justification = "Maintain public API", Scope = "member",
Target = "~M:Avro.File.DataFileWriter`1.OpenWriter(Avro.Generic.DatumWriter{`0},System.String,Avro.File.Codec)~Avro.File.IFileWriter{`0}")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch
general exception types", Justification = "Purposely catch any exception", Scope = "member",
Target = "~M:Avro.File.DataFileReader`1.Sync(System.Int64)")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch
general exception types", Justification = "Purposely catch any exception", Scope = "member",
Target = "~M:Avro.Specific.ObjectCreator.FindType(System.String)~System.Type")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch
general exception types", Justification = "Purposely catch any exception", Scope = "member",
Target = "~M:Avro.Specific.ObjectCreator.GetType(Avro.Schema)~System.Type")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare
visible instance fields", Justification = "Maintain public API", Scope = "member", Target
= "~F:Avro.CodeGen.namespaceLookup")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare
visible instance fields", Justification = "Maintain public API", Scope = "member", Target
= "~F:Avro.Generic.GenericFixed.value")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare
visible instance fields", Justification = "Maintain public API", Scope = "member", Target
= "~F:Avro.Field.aliases")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare
visible instance fields", Justification = "Maintain public API", Scope = "member", Target
= "~F:Avro.Field.Name")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1065:Do not raise
exceptions in unexpected locations", Justification = "Maintain public API", Scope = "member",
Target = "~P:Avro.EnumSchema.Item(System.Int32)")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1065:Do not raise
exceptions in unexpected locations", Justification = "Maintain public API", Scope = "member",
Target = "~P:Avro.Protocol.MD5")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize
strings to uppercase", Justification = "Maintain public API", Scope = "member", Target = "~M:Avro.Schema.GetTypeString(Avro.Schema.Type)~System.String")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize
strings to uppercase", Justification = "Maintain public API", Scope = "member", Target = "~P:Avro.UnnamedSchema.Name")]
diff --git a/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs b/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs
index 94fcdf1..323aa08 100644
--- a/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs
+++ b/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs
@@ -27,6 +27,13 @@ namespace Avro
         /// <summary>
         /// Initializes a new instance of the <see cref="ProtocolParseException"/>
class.
         /// </summary>
+        public ProtocolParseException()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ProtocolParseException"/>
class.
+        /// </summary>
         /// <param name="s">Exception message.</param>
         public ProtocolParseException(string s)
             : base(s)
diff --git a/lang/csharp/src/apache/main/Schema/AvroException.cs b/lang/csharp/src/apache/main/Schema/AvroException.cs
index 7d0eb2c..697ef98 100644
--- a/lang/csharp/src/apache/main/Schema/AvroException.cs
+++ b/lang/csharp/src/apache/main/Schema/AvroException.cs
@@ -27,6 +27,13 @@ namespace Avro
         /// <summary>
         /// Initializes a new instance of the <see cref="AvroException"/> class.
         /// </summary>
+        public AvroException()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="AvroException"/> class.
+        /// </summary>
         /// <param name="s">The message that describes the error.</param>
         public AvroException(string s)
             : base(s)
diff --git a/lang/csharp/src/apache/main/Schema/AvroTypeException.cs b/lang/csharp/src/apache/main/Schema/AvroTypeException.cs
index 141513f..d4e8eda 100644
--- a/lang/csharp/src/apache/main/Schema/AvroTypeException.cs
+++ b/lang/csharp/src/apache/main/Schema/AvroTypeException.cs
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+using System;
+
 namespace Avro
 {
     /// <summary>
@@ -26,10 +28,32 @@ namespace Avro
         /// <summary>
         /// Initializes a new instance of the <see cref="AvroTypeException"/> class.
         /// </summary>
+        public AvroTypeException()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="AvroTypeException"/> class.
+        /// </summary>
         /// <param name="s"></param>
         public AvroTypeException(string s)
             : base(s)
         {
         }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="AvroTypeException"/> class.
+        /// </summary>
+        /// <param name="message">
+        /// The error message that explains the reason for the exception.
+        /// </param>
+        /// <param name="innerException">
+        /// The exception that is the cause of the current exception, or a null reference
if no
+        /// inner exception is specified.
+        /// </param>
+        public AvroTypeException(string message, Exception innerException)
+            : base(message, innerException)
+        {
+        }
     }
 }
diff --git a/lang/csharp/src/apache/main/Schema/Field.cs b/lang/csharp/src/apache/main/Schema/Field.cs
index 1a441c8..eef8d20 100644
--- a/lang/csharp/src/apache/main/Schema/Field.cs
+++ b/lang/csharp/src/apache/main/Schema/Field.cs
@@ -57,8 +57,16 @@ namespace Avro
         /// <summary>
         /// List of aliases for the field name
         /// </summary>
+        [Obsolete("Use Aliases instead. This will be removed from the public API in a future
version.")]
         public readonly IList<string> aliases;
 
+#pragma warning disable CS0618 // Type or member is obsolete
+        /// <summary>
+        /// List of aliases for the field name.
+        /// </summary>
+        public IList<string> Aliases => aliases;
+#pragma warning restore CS0618 // Type or member is obsolete
+
         /// <summary>
         /// Position of the field within its record.
         /// </summary>
@@ -120,7 +128,9 @@ namespace Avro
             if (null == schema) throw new ArgumentNullException("type", "type cannot be null.");
             this.Schema = schema;
             this.Name = name;
+#pragma warning disable CS0618 // Type or member is obsolete
             this.aliases = aliases;
+#pragma warning restore CS0618 // Type or member is obsolete
             this.Pos = pos;
             this.Documentation = doc;
             this.DefaultValue = defaultValue;
@@ -154,12 +164,15 @@ namespace Avro
             if (null != this.Props)
                 this.Props.WriteJson(writer);
 
-            if (null != aliases)
+            if (null != Aliases)
             {
                 writer.WritePropertyName("aliases");
                 writer.WriteStartArray();
-                foreach (string name in aliases)
+                foreach (string name in Aliases)
+                {
                     writer.WriteValue(name);
+                }
+
                 writer.WriteEndArray();
             }
 
diff --git a/lang/csharp/src/apache/main/Schema/RecordSchema.cs b/lang/csharp/src/apache/main/Schema/RecordSchema.cs
index a089f05..3c6010b 100644
--- a/lang/csharp/src/apache/main/Schema/RecordSchema.cs
+++ b/lang/csharp/src/apache/main/Schema/RecordSchema.cs
@@ -96,8 +96,8 @@ namespace Avro
                     addToFieldMap(fieldMap, fieldName, field);
                     addToFieldMap(fieldAliasMap, fieldName, field);
 
-                    if (null != field.aliases)    // add aliases to field lookup map so reader
function will find it when writer field name appears only as an alias on the reader field
-                        foreach (string alias in field.aliases)
+                    if (null != field.Aliases)    // add aliases to field lookup map so reader
function will find it when writer field name appears only as an alias on the reader field
+                        foreach (string alias in field.Aliases)
                             addToFieldMap(fieldAliasMap, alias, field);
                 }
                 catch (SchemaParseException e)
@@ -315,8 +315,8 @@ namespace Avro
                 {
                     Field f2 = that[f.Name];
                     if (null == f2) // reader field not in writer field, check aliases of
reader field if any match with a writer field
-                        if (null != f.aliases)
-                            foreach (string alias in f.aliases)
+                        if (null != f.Aliases)
+                            foreach (string alias in f.Aliases)
                             {
                                 f2 = that[alias];
                                 if (null != f2) break;
diff --git a/lang/csharp/src/apache/main/Schema/Schema.cs b/lang/csharp/src/apache/main/Schema/Schema.cs
index 9e5ac3c..db0cb66 100644
--- a/lang/csharp/src/apache/main/Schema/Schema.cs
+++ b/lang/csharp/src/apache/main/Schema/Schema.cs
@@ -16,8 +16,6 @@
  * limitations under the License.
  */
 using System;
-using System.Collections.Generic;
-using System.Text;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json;
 
@@ -293,8 +291,7 @@ namespace Avro
         /// <returns>symbol name</returns>
         public static string GetTypeString(Type type)
         {
-            if (type != Type.Enumeration) return type.ToString().ToLower();
-            return "enum";
+            return type != Type.Enumeration ? type.ToString().ToLowerInvariant() : "enum";
         }
 
         /// <summary>
diff --git a/lang/csharp/src/apache/main/Schema/SchemaParseException.cs b/lang/csharp/src/apache/main/Schema/SchemaParseException.cs
index 4a6be90..532ad09 100644
--- a/lang/csharp/src/apache/main/Schema/SchemaParseException.cs
+++ b/lang/csharp/src/apache/main/Schema/SchemaParseException.cs
@@ -28,20 +28,32 @@ namespace Avro
         /// <summary>
         /// Initializes a new instance of the <see cref="SchemaParseException"/> class.
         /// </summary>
+        public SchemaParseException()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SchemaParseException"/> class.
+        /// </summary>
         /// <param name="s">Exception message.</param>
         public SchemaParseException(string s)
             : base(s)
         {
         }
+
         /// <summary>
-        /// Exception while parsing
+        /// Initializes a new instance of the <see cref="SchemaParseException"/> class.
         /// </summary>
-        /// <param name="s">Message</param>
-        /// <param name="inner">Inner Exception</param>
-        public SchemaParseException(string s, Exception inner)
-            : base(s, inner)
+        /// <param name="message">
+        /// The error message that explains the reason for the exception.
+        /// </param>
+        /// <param name="innerException">
+        /// The exception that is the cause of the current exception, or a null reference
if no
+        /// inner exception is specified.
+        /// </param>
+        public SchemaParseException(string message, Exception innerException)
+            : base(message, innerException)
         {
         }
-
     }
 }
diff --git a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs b/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
index d794963..5c876e5 100644
--- a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
+++ b/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
@@ -236,7 +236,9 @@ namespace Avro.Specific
                                 {
                                     return GenericNullableType.MakeGenericType(itemType);
                                 }
-                                catch (Exception) { }
+                                catch
+                                {
+                                }
                             }
 
                             return itemType;
diff --git a/lang/csharp/src/apache/main/Specific/SpecificException.cs b/lang/csharp/src/apache/main/Specific/SpecificException.cs
index c892a45..da5a362 100644
--- a/lang/csharp/src/apache/main/Specific/SpecificException.cs
+++ b/lang/csharp/src/apache/main/Specific/SpecificException.cs
@@ -25,6 +25,37 @@ namespace Avro.Specific
     /// </summary>
     public abstract class SpecificException : Exception, ISpecificRecord
     {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SpecificException"/> class.
+        /// </summary>
+        public SpecificException()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SpecificException"/> class.
+        /// </summary>
+        /// <param name="message">
+        /// The error message that explains the reason for the exception.
+        /// </param>
+        public SpecificException(string message) : base(message)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SpecificException"/> class.
+        /// </summary>
+        /// <param name="message">
+        /// The error message that explains the reason for the exception.
+        /// </param>
+        /// <param name="innerException">
+        /// The exception that is the cause of the current exception, or a null reference
if no
+        /// inner exception is specified.
+        /// </param>
+        public SpecificException(string message, Exception innerException) : base(message,
innerException)
+        {
+        }
+
         /// <inheritdoc/>
         public abstract Schema Schema { get; }
 
diff --git a/lang/csharp/stylecop.json b/lang/csharp/stylecop.json
new file mode 100644
index 0000000..82e8819
--- /dev/null
+++ b/lang/csharp/stylecop.json
@@ -0,0 +1,26 @@
+{
+  "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
+  "settings": {
+    "documentationRules": {
+      "companyName": "Apache Software Foundation (ASF)",
+      "fileNamingConvention": "stylecop"
+    },
+    "indentation": {
+      "indentationSize": 4,
+      "tabSize": 4,
+      "useTabs": false
+    },
+    "layoutRules": {
+      "newlineAtEndOfFile": "require",
+      "allowConsecutiveUsings": true
+    },
+    "orderingRules": {
+      "blankLinesBetweenUsingGroups": "allow",
+      "systemUsingDirectivesFirst": true,
+      "usingDirectivesPlacement": "outsideNamespace"
+    },
+    "readabilityRules": {
+      "allowBuiltInTypeAliases": false
+    }
+  }
+}


Mime
View raw message