You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/07/18 07:43:28 UTC
[GitHub] [avro] github-code-scanning[bot] commented on a diff in pull request #1728: AVRO-3540: Support dictionaries keyed by types other than string
github-code-scanning[bot] commented on code in PR #1728:
URL: https://github.com/apache/avro/pull/1728#discussion_r923050461
##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -290,5 +304,26 @@
break;
}
}
+ private static Type FindOpenGenericInterface(
+ Type expected,
+ Type actual)
+ {
+ if (actual.IsGenericType &&
+ actual.GetGenericTypeDefinition() == expected)
+ {
+ return actual;
+ }
+
+ Type[] interfaces = actual.GetInterfaces();
+ foreach (Type interfaceType in interfaces)
+ {
+ if (interfaceType.IsGenericType &&
+ interfaceType.GetGenericTypeDefinition() == expected)
+ {
+ return interfaceType;
+ }
+ }
Review Comment:
## Missed opportunity to use Where
This foreach loop implicitly filters its target sequence [here](1) - consider filtering the sequence explicitly using '.Where(...)'.
[Show more details](https://github.com/apache/avro/security/code-scanning/2779)
##########
lang/csharp/src/apache/test/Reflect/TestReflect.cs:
##########
@@ -21,12 +21,172 @@
using NUnit.Framework;
using Avro.IO;
using Avro.Reflect;
+using System.Collections.Generic;
+using System;
+using Avro.Specific;
+using System.Linq;
+using System.Diagnostics.CodeAnalysis;
namespace Avro.Test
{
[TestFixture]
class TestReflect
{
+ public class IDictionaryTestClass : IDictionary<string, int>
+ {
+ Dictionary<string, int> _pairs = new Dictionary<string, int>();
Review Comment:
## Missed 'readonly' opportunity
Field '_pairs' can be 'readonly'.
[Show more details](https://github.com/apache/avro/security/code-scanning/2778)
##########
lang/csharp/src/apache/main/Reflect/DotnetProperty.cs:
##########
@@ -136,5 +142,27 @@
_property.SetValue(o, v);
}
}
+
+ private static Type FindOpenGenericInterface(
+ Type expected,
+ Type actual)
+ {
+ if (actual.IsGenericType &&
+ actual.GetGenericTypeDefinition() == expected)
+ {
+ return actual;
+ }
+
+ Type[] interfaces = actual.GetInterfaces();
+ foreach (Type interfaceType in interfaces)
+ {
+ if (interfaceType.IsGenericType &&
+ interfaceType.GetGenericTypeDefinition() == expected)
+ {
+ return interfaceType;
+ }
+ }
Review Comment:
## Missed opportunity to use Where
This foreach loop implicitly filters its target sequence [here](1) - consider filtering the sequence explicitly using '.Where(...)'.
[Show more details](https://github.com/apache/avro/security/code-scanning/2780)
##########
lang/csharp/src/apache/main/Reflect/ReflectDefaultWriter.cs:
##########
@@ -203,5 +232,26 @@
throw new AvroException("Unknown schema type: " + sc.Tag);
}
}
+ private static Type FindOpenGenericInterface(
+ Type expected,
+ Type actual)
+ {
+ if (actual.IsGenericType &&
+ actual.GetGenericTypeDefinition() == expected)
+ {
+ return actual;
+ }
+
+ Type[] interfaces = actual.GetInterfaces();
+ foreach (Type interfaceType in interfaces)
+ {
+ if (interfaceType.IsGenericType &&
+ interfaceType.GetGenericTypeDefinition() == expected)
+ {
+ return interfaceType;
+ }
+ }
Review Comment:
## Missed opportunity to use Where
This foreach loop implicitly filters its target sequence [here](1) - consider filtering the sequence explicitly using '.Where(...)'.
[Show more details](https://github.com/apache/avro/security/code-scanning/2781)
--
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: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org