paulirwin commented on code in PR #1091:
URL: https://github.com/apache/lucenenet/pull/1091#discussion_r1904689317


##########
src/Lucene.Net.Analysis.Common/Analysis/Util/AnalysisSPILoader.cs:
##########
@@ -36,7 +36,7 @@ internal sealed class AnalysisSPILoader<S> where S : 
AbstractAnalysisFactory
         private readonly string[] suffixes;
 
         public AnalysisSPILoader()
-            : this(new string[] { typeof(S).Name })
+            : this(new string[] { nameof(S) })

Review Comment:
   Unfortunately we can't use that here, because S is a generic type parameter, 
so this will yield `"S"` instead of whatever type is passed into S.



##########
src/Lucene.Net.Analysis.Common/Analysis/NGram/EdgeNGramTokenizerFactory.cs:
##########
@@ -61,7 +61,7 @@ public override Tokenizer 
Create(AttributeSource.AttributeFactory factory, TextR
                 EdgeNGramTokenFilter.Side sideEnum;
                 if (!Enum.TryParse(this.side, true, out sideEnum))
                 {
-                    throw new 
ArgumentException(typeof(EdgeNGramTokenizer).Name + " does not support backward 
n-grams as of Lucene 4.4");
+                    throw new ArgumentException(nameof(EdgeNGramTokenizer) + " 
does not support backward n-grams as of Lucene 4.4");

Review Comment:
   Let's go ahead and change this to use string interpolation, 
`$"{nameof(EdgeNGramTokenizer)} does not support backward n-grams as of Lucene 
4.4"`. I know at least Rider/ReSharper has a quick fix for this, hopefully 
Visual Studio does as well if you use that.



##########
src/Lucene.Net/Util/CommandLineUtil.cs:
##########
@@ -43,21 +43,21 @@ public static FSDirectory NewFSDirectory(string clazzName, 
DirectoryInfo dir)
 
                 // LUCENENET: In .NET, we get a null when the class is not 
found, so we need to throw here for compatibility
                 if (clazz is null)
-                    throw new ArgumentException(typeof(FSDirectory).Name + " 
implementation not found: " + clazzName);
+                    throw new ArgumentException(nameof(FSDirectory) + " 
implementation not found: " + clazzName);

Review Comment:
   Let's convert these usages in this file to string interpolation.



##########
src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs:
##########
@@ -66,13 +66,13 @@ public abstract class PerFieldDocValuesFormat : 
DocValuesFormat
         /// <see cref="FieldInfo"/> attribute name used to store the
         /// format name for each field.
         /// </summary>
-        public static readonly string PER_FIELD_FORMAT_KEY = 
typeof(PerFieldDocValuesFormat).Name + ".format";
+        public static readonly string PER_FIELD_FORMAT_KEY = 
nameof(PerFieldDocValuesFormat) + ".format";

Review Comment:
   If possible, convert these to `public const string`



##########
src/Lucene.Net/Codecs/Lucene3x/Lucene3xSegmentInfoFormat.cs:
##########
@@ -62,12 +62,12 @@ public class Lucene3xSegmentInfoFormat : SegmentInfoFormat
         public override SegmentInfoWriter SegmentInfoWriter => throw 
UnsupportedOperationException.Create("this codec can only be used for reading");
 
         // only for backwards compat
-        public static readonly string DS_OFFSET_KEY = 
typeof(Lucene3xSegmentInfoFormat).Name + ".dsoffset";
+        public static readonly string DS_OFFSET_KEY = 
nameof(Lucene3xSegmentInfoFormat) + ".dsoffset";

Review Comment:
   I think these can be converted to `public const string`s now.



##########
src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs:
##########
@@ -137,8 +137,8 @@ public override FieldInfos Read(Directory directory, string 
segmentName, string
             }
         }
 
-        internal static readonly string LEGACY_DV_TYPE_KEY = 
typeof(Lucene40FieldInfosReader).Name + ".dvtype";
-        internal static readonly string LEGACY_NORM_TYPE_KEY = 
typeof(Lucene40FieldInfosReader).Name + ".normtype";
+        internal static readonly string LEGACY_DV_TYPE_KEY = 
nameof(Lucene40FieldInfosReader) + ".dvtype";

Review Comment:
   If possible, convert these to `internal const string`



##########
src/Lucene.Net.TestFramework/Util/TestSecurityManager.cs:
##########
@@ -71,7 +71,7 @@ public PrivilegedActionAnonymousClass(TestSecurityManager 
outerInstance, int sta
 
           public override void Run()
           {
-            const string systemClassName = typeof(System).Name, 
runtimeClassName = typeof(Runtime).Name;
+            const string systemClassName = nameof(System), runtimeClassName = 
nameof(Runtime);

Review Comment:
   Interestingly, the prior code didn't work. `typeof(T).Name` is not a 
constant expression. Nothing to do here, it's just interesting since this code 
is `#if` disabled.



##########
src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs:
##########
@@ -60,13 +60,13 @@ public abstract class PerFieldPostingsFormat : 
PostingsFormat
         /// <see cref="FieldInfo"/> attribute name used to store the
         /// format name for each field.
         /// </summary>
-        public static readonly string PER_FIELD_FORMAT_KEY = 
typeof(PerFieldPostingsFormat).Name + ".format";
+        public static readonly string PER_FIELD_FORMAT_KEY = 
nameof(PerFieldPostingsFormat) + ".format";

Review Comment:
   If possible, convert these to `public const string`



##########
src/Lucene.Net/Support/Util/NamedServiceFactory.cs:
##########
@@ -129,7 +129,7 @@ protected static string GetCanonicalName(Type type)
                 genericSuffix = "Generic" + name.Substring(genericIndex + 1);
                 name = name.Substring(0, genericIndex);
             }
-            string serviceName = typeof(TService).Name;
+            string serviceName = nameof(TService);

Review Comment:
   We have to revert this, since `TService` is a generic type parameter. We 
need the runtime name of the type parameter, not the string `"TService"` here.



-- 
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: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to