github-code-scanning[bot] commented on code in PR #1823:
URL: https://github.com/apache/avro/pull/1823#discussion_r944142972


##########
lang/csharp/src/apache/main/Reflect/Service/ReflectFactory.cs:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Text;
+using Avro.Reflect.Model;
+
+namespace Avro.Reflect.Service
+{
+    /// <summary>
+    /// Factory to create objects for reflest serialixation and deserialization
+    /// </summary>
+    public class ReflectFactory : IReflectFactory
+    {
+        private readonly IReflectCache _refletCache;
+        private readonly IArrayService _arrayService;
+        private readonly IDotnetclassFactory _dotnetclassFactory;
+
+        /// <summary>
+        /// Public constructor
+        /// </summary>
+        public ReflectFactory(
+            IReflectCache refletCache,
+            IArrayService arrayService,
+            IDotnetclassFactory dotnetclassFactory)
+        {
+            _refletCache = refletCache;
+            _arrayService = arrayService;
+            _dotnetclassFactory = dotnetclassFactory;
+        }
+
+        /// <summary>
+        /// Create reflect reader
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <param name="readerSchema"></param>
+        /// <returns></returns>
+        public ReflectReader<T> CreateReader<T>(Schema writerSchema, Schema 
readerSchema)
+        {
+            LoadClassCache(typeof(T), readerSchema);
+
+            return new ReflectReader<T>(writerSchema, readerSchema, 
_refletCache, _arrayService);
+        }
+
+        /// <summary>
+        /// Create reflect writer
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <returns></returns>
+        public ReflectWriter<T> CreateWriter<T>(Schema writerSchema)
+        {
+            LoadClassCache(typeof(T), writerSchema);
+
+            return new ReflectWriter<T>(writerSchema, _refletCache, 
_arrayService);
+        }
+
+        internal void LoadClassCache(Type objType, Schema s)
+        {
+            ConcurrentDictionary<string, Schema> previousFields = new 
ConcurrentDictionary<string, Schema>();

Review Comment:
   ## Container contents are never accessed
   
   The contents of this container are never accessed.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2892)



##########
lang/csharp/src/apache/main/Reflect/Service/ReflectFactory.cs:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Text;
+using Avro.Reflect.Model;
+
+namespace Avro.Reflect.Service
+{
+    /// <summary>
+    /// Factory to create objects for reflest serialixation and deserialization
+    /// </summary>
+    public class ReflectFactory : IReflectFactory
+    {
+        private readonly IReflectCache _refletCache;
+        private readonly IArrayService _arrayService;
+        private readonly IDotnetclassFactory _dotnetclassFactory;
+
+        /// <summary>
+        /// Public constructor
+        /// </summary>
+        public ReflectFactory(
+            IReflectCache refletCache,
+            IArrayService arrayService,
+            IDotnetclassFactory dotnetclassFactory)
+        {
+            _refletCache = refletCache;
+            _arrayService = arrayService;
+            _dotnetclassFactory = dotnetclassFactory;
+        }
+
+        /// <summary>
+        /// Create reflect reader
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <param name="readerSchema"></param>
+        /// <returns></returns>
+        public ReflectReader<T> CreateReader<T>(Schema writerSchema, Schema 
readerSchema)
+        {
+            LoadClassCache(typeof(T), readerSchema);
+
+            return new ReflectReader<T>(writerSchema, readerSchema, 
_refletCache, _arrayService);
+        }
+
+        /// <summary>
+        /// Create reflect writer
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <returns></returns>
+        public ReflectWriter<T> CreateWriter<T>(Schema writerSchema)
+        {
+            LoadClassCache(typeof(T), writerSchema);
+
+            return new ReflectWriter<T>(writerSchema, _refletCache, 
_arrayService);
+        }
+
+        internal void LoadClassCache(Type objType, Schema s)
+        {
+            ConcurrentDictionary<string, Schema> previousFields = new 
ConcurrentDictionary<string, Schema>();

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [previousFields](1) is useless, since its value is never 
read.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2889)



##########
lang/csharp/src/apache/main/Reflect/Service/ReflectFactory.cs:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Text;
+using Avro.Reflect.Model;
+
+namespace Avro.Reflect.Service
+{
+    /// <summary>
+    /// Factory to create objects for reflest serialixation and deserialization
+    /// </summary>
+    public class ReflectFactory : IReflectFactory
+    {
+        private readonly IReflectCache _refletCache;
+        private readonly IArrayService _arrayService;
+        private readonly IDotnetclassFactory _dotnetclassFactory;
+
+        /// <summary>
+        /// Public constructor
+        /// </summary>
+        public ReflectFactory(
+            IReflectCache refletCache,
+            IArrayService arrayService,
+            IDotnetclassFactory dotnetclassFactory)
+        {
+            _refletCache = refletCache;
+            _arrayService = arrayService;
+            _dotnetclassFactory = dotnetclassFactory;
+        }
+
+        /// <summary>
+        /// Create reflect reader
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <param name="readerSchema"></param>
+        /// <returns></returns>
+        public ReflectReader<T> CreateReader<T>(Schema writerSchema, Schema 
readerSchema)
+        {
+            LoadClassCache(typeof(T), readerSchema);
+
+            return new ReflectReader<T>(writerSchema, readerSchema, 
_refletCache, _arrayService);
+        }
+
+        /// <summary>
+        /// Create reflect writer
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <returns></returns>
+        public ReflectWriter<T> CreateWriter<T>(Schema writerSchema)
+        {
+            LoadClassCache(typeof(T), writerSchema);
+
+            return new ReflectWriter<T>(writerSchema, _refletCache, 
_arrayService);
+        }
+
+        internal void LoadClassCache(Type objType, Schema s)
+        {
+            ConcurrentDictionary<string, Schema> previousFields = new 
ConcurrentDictionary<string, Schema>();
+
+            switch (s)
+            {
+                case RecordSchema rs:
+                    if (!objType.IsClass)
+                    {
+                        throw new AvroException($"Cant map scalar type 
{objType.Name} to record {rs.Fullname}");
+                    }
+
+                    if (typeof(byte[]).IsAssignableFrom(objType)
+                        || typeof(string).IsAssignableFrom(objType)
+                        || typeof(IEnumerable).IsAssignableFrom(objType)
+                        || typeof(IDictionary).IsAssignableFrom(objType))
+                    {
+                        throw new AvroException($"Cant map type {objType.Name} 
to record {rs.Fullname}");
+                    }
+
+                    AddClassNameMapItem(rs, objType);
+                    var c = _refletCache.GetClass(rs.Fullname);

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [c](1) is useless, since its value is never read.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2890)



##########
lang/csharp/src/apache/main/Reflect/Service/ReflectFactory.cs:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Text;
+using Avro.Reflect.Model;
+
+namespace Avro.Reflect.Service
+{
+    /// <summary>
+    /// Factory to create objects for reflest serialixation and deserialization
+    /// </summary>
+    public class ReflectFactory : IReflectFactory
+    {
+        private readonly IReflectCache _refletCache;
+        private readonly IArrayService _arrayService;
+        private readonly IDotnetclassFactory _dotnetclassFactory;
+
+        /// <summary>
+        /// Public constructor
+        /// </summary>
+        public ReflectFactory(
+            IReflectCache refletCache,
+            IArrayService arrayService,
+            IDotnetclassFactory dotnetclassFactory)
+        {
+            _refletCache = refletCache;
+            _arrayService = arrayService;
+            _dotnetclassFactory = dotnetclassFactory;
+        }
+
+        /// <summary>
+        /// Create reflect reader
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <param name="readerSchema"></param>
+        /// <returns></returns>
+        public ReflectReader<T> CreateReader<T>(Schema writerSchema, Schema 
readerSchema)
+        {
+            LoadClassCache(typeof(T), readerSchema);
+
+            return new ReflectReader<T>(writerSchema, readerSchema, 
_refletCache, _arrayService);
+        }
+
+        /// <summary>
+        /// Create reflect writer
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="writerSchema"></param>
+        /// <returns></returns>
+        public ReflectWriter<T> CreateWriter<T>(Schema writerSchema)
+        {
+            LoadClassCache(typeof(T), writerSchema);
+
+            return new ReflectWriter<T>(writerSchema, _refletCache, 
_arrayService);
+        }
+
+        internal void LoadClassCache(Type objType, Schema s)
+        {
+            ConcurrentDictionary<string, Schema> previousFields = new 
ConcurrentDictionary<string, Schema>();
+
+            switch (s)
+            {
+                case RecordSchema rs:
+                    if (!objType.IsClass)
+                    {
+                        throw new AvroException($"Cant map scalar type 
{objType.Name} to record {rs.Fullname}");
+                    }
+
+                    if (typeof(byte[]).IsAssignableFrom(objType)
+                        || typeof(string).IsAssignableFrom(objType)
+                        || typeof(IEnumerable).IsAssignableFrom(objType)
+                        || typeof(IDictionary).IsAssignableFrom(objType))
+                    {
+                        throw new AvroException($"Cant map type {objType.Name} 
to record {rs.Fullname}");
+                    }
+
+                    AddClassNameMapItem(rs, objType);
+                    var c = _refletCache.GetClass(rs.Fullname);
+                    foreach (var f in rs.Fields)

Review Comment:
   ## Useless assignment to local variable
   
   This assignment to [f](1) is useless, since its value is never read.
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2891)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to