CA1507: Use nameof instead of string
diff --git a/src/Lucene.Net/Analysis/Analyzer.cs b/src/Lucene.Net/Analysis/Analyzer.cs
index 31aa3a5..978658c 100644
--- a/src/Lucene.Net/Analysis/Analyzer.cs
+++ b/src/Lucene.Net/Analysis/Analyzer.cs
@@ -482,9 +482,7 @@
public AnonymousAnalyzer(Func<string, TextReader, TokenStreamComponents> createComponents, Func<string, TextReader, TextReader> initReader, ReuseStrategy reuseStrategy)
: base(reuseStrategy)
{
- if (createComponents == null)
- throw new ArgumentNullException("createComponents");
- this.createComponents = createComponents;
+ this.createComponents = createComponents ?? throw new ArgumentNullException(nameof(createComponents));
this.initReader = initReader;
}
diff --git a/src/Lucene.Net/Analysis/Tokenizer.cs b/src/Lucene.Net/Analysis/Tokenizer.cs
index 249b60f..f94a5bb 100644
--- a/src/Lucene.Net/Analysis/Tokenizer.cs
+++ b/src/Lucene.Net/Analysis/Tokenizer.cs
@@ -44,11 +44,7 @@
/// Construct a token stream processing the given input. </summary>
protected internal Tokenizer(TextReader input)
{
- if (input == null)
- {
- throw new ArgumentNullException("input", "input must not be null");
- }
- this.inputPending = input;
+ this.inputPending = input ?? throw new ArgumentNullException(nameof(input), "input must not be null");
}
/// <summary>
@@ -59,7 +55,7 @@
{
if (input == null)
{
- throw new ArgumentNullException("input", "input must not be null");
+ throw new ArgumentNullException(nameof(input), "input must not be null");
}
this.inputPending = input;
}
diff --git a/src/Lucene.Net/Codecs/Codec.cs b/src/Lucene.Net/Codecs/Codec.cs
index b489c8c..ea731f4 100644
--- a/src/Lucene.Net/Codecs/Codec.cs
+++ b/src/Lucene.Net/Codecs/Codec.cs
@@ -71,9 +71,7 @@
/// <exception cref="ArgumentNullException">The <paramref name="codecFactory"/> parameter is <c>null</c>.</exception>
public static void SetCodecFactory(ICodecFactory codecFactory)
{
- if (codecFactory == null)
- throw new ArgumentNullException("codecFactory");
- Codec.codecFactory = codecFactory;
+ Codec.codecFactory = codecFactory ?? throw new ArgumentNullException(nameof(codecFactory));
}
/// <summary>
diff --git a/src/Lucene.Net/Codecs/DocValuesFormat.cs b/src/Lucene.Net/Codecs/DocValuesFormat.cs
index dcd1397..91708bd 100644
--- a/src/Lucene.Net/Codecs/DocValuesFormat.cs
+++ b/src/Lucene.Net/Codecs/DocValuesFormat.cs
@@ -83,9 +83,7 @@
/// <exception cref="ArgumentNullException">The <paramref name="docValuesFormatFactory"/> parameter is <c>null</c>.</exception>
public static void SetDocValuesFormatFactory(IDocValuesFormatFactory docValuesFormatFactory)
{
- if (docValuesFormatFactory == null)
- throw new ArgumentNullException("docValuesFormatFactory");
- DocValuesFormat.docValuesFormatFactory = docValuesFormatFactory;
+ DocValuesFormat.docValuesFormatFactory = docValuesFormatFactory ?? throw new ArgumentNullException(nameof(docValuesFormatFactory));
}
/// <summary>
diff --git a/src/Lucene.Net/Codecs/PostingsFormat.cs b/src/Lucene.Net/Codecs/PostingsFormat.cs
index a391345..2b4f352 100644
--- a/src/Lucene.Net/Codecs/PostingsFormat.cs
+++ b/src/Lucene.Net/Codecs/PostingsFormat.cs
@@ -86,9 +86,7 @@
/// <exception cref="ArgumentNullException">The <paramref name="postingsFormatFactory"/> parameter is <c>null</c>.</exception>
public static void SetPostingsFormatFactory(IPostingsFormatFactory postingsFormatFactory)
{
- if (postingsFormatFactory == null)
- throw new ArgumentNullException("postingsFormatFactory");
- PostingsFormat.postingsFormatFactory = postingsFormatFactory;
+ PostingsFormat.postingsFormatFactory = postingsFormatFactory ?? throw new ArgumentNullException(nameof(postingsFormatFactory));
}
/// <summary>
diff --git a/src/Lucene.Net/Document/Field.cs b/src/Lucene.Net/Document/Field.cs
index 4ad26a8..25b298a 100644
--- a/src/Lucene.Net/Document/Field.cs
+++ b/src/Lucene.Net/Document/Field.cs
@@ -140,16 +140,8 @@
/// is <c>null</c>. </exception>
protected internal Field(string name, FieldType type)
{
- if (name == null)
- {
- throw new ArgumentNullException("name", "name cannot be null");
- }
- if (type == null)
- {
- throw new ArgumentNullException("type", "type cannot be null");
- }
- this.m_name = name;
- this.m_type = type;
+ this.m_name = name ?? throw new ArgumentNullException(nameof(name), "name cannot be null");
+ this.m_type = type ?? throw new ArgumentNullException(nameof(type), "type cannot be null");
}
/// <summary>
@@ -165,15 +157,15 @@
{
if (name == null)
{
- throw new ArgumentNullException("name", "name cannot be null");
+ throw new ArgumentNullException(nameof(name), "name cannot be null");
}
if (type == null)
{
- throw new ArgumentNullException("type", "type cannot be null");
+ throw new ArgumentNullException(nameof(type), "type cannot be null");
}
if (reader == null)
{
- throw new ArgumentNullException("reader", "reader cannot be null");
+ throw new ArgumentNullException(nameof(reader), "reader cannot be null");
}
if (type.IsStored)
{
@@ -202,15 +194,15 @@
{
if (name == null)
{
- throw new ArgumentNullException("name", "name cannot be null");
+ throw new ArgumentNullException(nameof(name), "name cannot be null");
}
if (tokenStream == null)
{
- throw new ArgumentNullException("tokenStream", "tokenStream cannot be null");
+ throw new ArgumentNullException(nameof(tokenStream), "tokenStream cannot be null");
}
if (type == null)
{
- throw new ArgumentNullException("type", "type cannot be null");
+ throw new ArgumentNullException(nameof(type), "type cannot be null");
}
if (!type.IsIndexed || !type.IsTokenized)
{
@@ -279,11 +271,11 @@
{
if (name == null)
{
- throw new ArgumentNullException("name", "name cannot be null");
+ throw new ArgumentNullException(nameof(name), "name cannot be null");
}
if (type == null)
{
- throw new ArgumentNullException("type", "type cannot be null");
+ throw new ArgumentNullException(nameof(type), "type cannot be null");
}
if (type.IsIndexed)
{
@@ -309,15 +301,15 @@
{
if (name == null)
{
- throw new ArgumentNullException("name", "name cannot be null");
+ throw new ArgumentNullException(nameof(name), "name cannot be null");
}
if (value == null)
{
- throw new ArgumentNullException("value", "value cannot be null");
+ throw new ArgumentNullException(nameof(value), "value cannot be null");
}
if (type == null)
{
- throw new ArgumentNullException("type", "type cannot be null");
+ throw new ArgumentNullException(nameof(type), "type cannot be null");
}
if (!type.IsStored && !type.IsIndexed)
{
@@ -1313,7 +1305,7 @@
return false;
default:
- throw new ArgumentOutOfRangeException("store", "Invalid value for Field.Store");
+ throw new ArgumentOutOfRangeException(nameof(store), "Invalid value for Field.Store");
}
}
@@ -1332,7 +1324,7 @@
return true;
default:
- throw new ArgumentOutOfRangeException("index", "Invalid value for Field.Index");
+ throw new ArgumentOutOfRangeException(nameof(index), "Invalid value for Field.Index");
}
}
@@ -1351,7 +1343,7 @@
return true;
default:
- throw new ArgumentOutOfRangeException("index", "Invalid value for Field.Index");
+ throw new ArgumentOutOfRangeException(nameof(index), "Invalid value for Field.Index");
}
}
@@ -1370,7 +1362,7 @@
return true;
default:
- throw new ArgumentOutOfRangeException("index", "Invalid value for Field.Index");
+ throw new ArgumentOutOfRangeException(nameof(index), "Invalid value for Field.Index");
}
}
@@ -1389,7 +1381,7 @@
return true;
default:
- throw new ArgumentOutOfRangeException("tv", "Invalid value for Field.TermVector");
+ throw new ArgumentOutOfRangeException(nameof(tv), "Invalid value for Field.TermVector");
}
}
@@ -1408,7 +1400,7 @@
return true;
default:
- throw new ArgumentOutOfRangeException("tv", "Invalid value for Field.TermVector");
+ throw new ArgumentOutOfRangeException(nameof(tv), "Invalid value for Field.TermVector");
}
}
@@ -1427,7 +1419,7 @@
return true;
default:
- throw new ArgumentOutOfRangeException("tv", "Invalid value for Field.TermVector");
+ throw new ArgumentOutOfRangeException(nameof(tv), "Invalid value for Field.TermVector");
}
}
diff --git a/src/Lucene.Net/Search/Collector.cs b/src/Lucene.Net/Search/Collector.cs
index be308d5..393008b 100644
--- a/src/Lucene.Net/Search/Collector.cs
+++ b/src/Lucene.Net/Search/Collector.cs
@@ -258,19 +258,10 @@
public AnonymousCollector(Action<Scorer> setScorer, Action<int> collect, Action<AtomicReaderContext> setNextReader, Func<bool> acceptsDocsOutOfOrder)
{
- if (setScorer == null)
- throw new ArgumentNullException("setScorer");
- if (collect == null)
- throw new ArgumentNullException("collect");
- if (setNextReader == null)
- throw new ArgumentNullException("setNextReader");
- if (acceptsDocsOutOfOrder == null)
- throw new ArgumentNullException("acceptsDocsOutOfOrder");
-
- this.setScorer = setScorer;
- this.collect = collect;
- this.setNextReader = setNextReader;
- this.acceptsDocsOutOfOrder = acceptsDocsOutOfOrder;
+ this.setScorer = setScorer ?? throw new ArgumentNullException(nameof(setScorer));
+ this.collect = collect ?? throw new ArgumentNullException(nameof(collect));
+ this.setNextReader = setNextReader ?? throw new ArgumentNullException(nameof(setNextReader));
+ this.acceptsDocsOutOfOrder = acceptsDocsOutOfOrder ?? throw new ArgumentNullException(nameof(acceptsDocsOutOfOrder));
}
public bool AcceptsDocsOutOfOrder => this.acceptsDocsOutOfOrder();
diff --git a/src/Lucene.Net/Search/DocIdSet.cs b/src/Lucene.Net/Search/DocIdSet.cs
index 549decf..9c78d24 100644
--- a/src/Lucene.Net/Search/DocIdSet.cs
+++ b/src/Lucene.Net/Search/DocIdSet.cs
@@ -206,10 +206,7 @@
public AnonymousDocIdSet(Func<DocIdSetIterator> getIterator, Func<IBits> bits, Func<bool> isCacheable)
{
- if (getIterator == null)
- throw new ArgumentNullException("getIterator");
-
- this.getIterator = getIterator;
+ this.getIterator = getIterator ?? throw new ArgumentNullException(nameof(getIterator));
this.bits = bits;
this.isCacheable = isCacheable;
}
diff --git a/src/Lucene.Net/Store/Lock.cs b/src/Lucene.Net/Store/Lock.cs
index f0cd1ac..703bfca 100644
--- a/src/Lucene.Net/Store/Lock.cs
+++ b/src/Lucene.Net/Store/Lock.cs
@@ -233,10 +233,7 @@
public AnonymousWith(Lock @lock, int lockWaitTimeout, Func<T> doBody)
: base(@lock, lockWaitTimeout)
{
- if (doBody == null)
- throw new ArgumentNullException("doBody");
-
- this.doBody = doBody;
+ this.doBody = doBody ?? throw new ArgumentNullException(nameof(doBody));
}
protected override T DoBody()
diff --git a/src/Lucene.Net/Store/MMapDirectory.cs b/src/Lucene.Net/Store/MMapDirectory.cs
index 523e97e..2a4c941 100644
--- a/src/Lucene.Net/Store/MMapDirectory.cs
+++ b/src/Lucene.Net/Store/MMapDirectory.cs
@@ -236,7 +236,7 @@
: base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, true)
{
this.outerInstance = outerInstance;
- this.fc = fc ?? throw new ArgumentNullException("fc");
+ this.fc = fc ?? throw new ArgumentNullException(nameof(fc));
this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length));
}
diff --git a/src/Lucene.Net/Support/Arrays.cs b/src/Lucene.Net/Support/Arrays.cs
index ce9ae93..6d5c662 100644
--- a/src/Lucene.Net/Support/Arrays.cs
+++ b/src/Lucene.Net/Support/Arrays.cs
@@ -106,9 +106,9 @@
if (fromIndex > toIndex)
throw new ArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
if (fromIndex < 0)
- throw new ArgumentOutOfRangeException("fromIndex");
+ throw new ArgumentOutOfRangeException(nameof(fromIndex));
if (toIndex > a.Length)
- throw new ArgumentOutOfRangeException("toIndex");
+ throw new ArgumentOutOfRangeException(nameof(toIndex));
for (int i = fromIndex; i < toIndex; i++)
{
diff --git a/src/Lucene.Net/Support/EnumerableExtensions.cs b/src/Lucene.Net/Support/EnumerableExtensions.cs
index 7c6ca6e..d415dfc 100644
--- a/src/Lucene.Net/Support/EnumerableExtensions.cs
+++ b/src/Lucene.Net/Support/EnumerableExtensions.cs
@@ -99,10 +99,10 @@
public static IEnumerable<T> TakeAllButLast<T>(this IEnumerable<T> source, int n)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
if (n < 0)
- throw new ArgumentOutOfRangeException("n",
+ throw new ArgumentOutOfRangeException(nameof(n),
"Argument n should be non-negative.");
return TakeAllButLastImpl(source, n);
diff --git a/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs b/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs
index a7150a2..3e26cf5 100644
--- a/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs
+++ b/src/Lucene.Net/Support/Threading/LimitedConcurrencyLevelTaskScheduler.cs
@@ -79,7 +79,7 @@
// Creates a new instance with the specified degree of parallelism.
public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism)
{
- if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException("maxDegreeOfParallelism");
+ if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException(nameof(maxDegreeOfParallelism));
_maxDegreeOfParallelism = maxDegreeOfParallelism;
}
diff --git a/src/Lucene.Net/Support/Util/ServiceNameAttribute.cs b/src/Lucene.Net/Support/Util/ServiceNameAttribute.cs
index 503d762..dfb292c 100644
--- a/src/Lucene.Net/Support/Util/ServiceNameAttribute.cs
+++ b/src/Lucene.Net/Support/Util/ServiceNameAttribute.cs
@@ -34,7 +34,7 @@
public ServiceNameAttribute(string name)
{
if (string.IsNullOrEmpty(name))
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
this.Name = name;
}
diff --git a/src/Lucene.Net/Util/LongsRef.cs b/src/Lucene.Net/Util/LongsRef.cs
index 2776788..04f77cf 100644
--- a/src/Lucene.Net/Util/LongsRef.cs
+++ b/src/Lucene.Net/Util/LongsRef.cs
@@ -59,11 +59,7 @@
get => longs;
set
{
- if (value == null)
- {
- throw new ArgumentNullException("value");
- }
- longs = value;
+ longs = value ?? throw new ArgumentNullException(nameof(value));
}
}
private long[] longs;