Skip to content

Commit f4fc5be

Browse files
committed
feat: Nullable enabled
1 parent a0faff0 commit f4fc5be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+304
-221
lines changed

src/Directory.Build.props

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@
2424
<PropertyGroup Condition="'$(MSBuildProjectName)' != 'Examine.Web.Demo' AND '$(MSBuildProjectName)' != 'Examine.Test'">
2525
<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
2626
</PropertyGroup>
27-
27+
28+
<!-- Disable the nullable warnings when compiling for .NET Standard 2.0 -->
29+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
30+
<NoWarn>$(NoWarn);nullable</NoWarn>
31+
</PropertyGroup>
2832
</Project>

src/Examine.Core/BaseIndexProvider.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected BaseIndexProvider(ILoggerFactory loggerFactory, string name,
3939
/// <summary>
4040
/// A validator to validate a value set before it's indexed
4141
/// </summary>
42-
public IValueSetValidator ValueSetValidator => _indexOptions.Validator;
42+
public IValueSetValidator? ValueSetValidator => _indexOptions.Validator;
4343

4444
/// <summary>
4545
/// Ensures that the node being indexed is of a correct type
@@ -113,13 +113,13 @@ public void DeleteFromIndex(IEnumerable<string> itemIds)
113113
#region Events
114114

115115
/// <inheritdoc />
116-
public event EventHandler<IndexOperationEventArgs> IndexOperationComplete;
116+
public event EventHandler<IndexOperationEventArgs>? IndexOperationComplete;
117117

118118
/// <inheritdoc />
119-
public event EventHandler<IndexingErrorEventArgs> IndexingError;
119+
public event EventHandler<IndexingErrorEventArgs>? IndexingError;
120120

121121
/// <inheritdoc />
122-
public event EventHandler<IndexingItemEventArgs> TransformingIndexValues;
122+
public event EventHandler<IndexingItemEventArgs>? TransformingIndexValues;
123123

124124
#endregion
125125

src/Examine.Core/BaseSearchProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ protected BaseSearchProvider(string name)
2222
/// <param name="searchText"></param>
2323
/// <param name="maxResults"></param>
2424
/// <returns></returns>
25-
public abstract ISearchResults Search(string searchText, QueryOptions options = null);
25+
public abstract ISearchResults Search(string searchText, QueryOptions? options = null);
2626

2727
/// <inheritdoc />
28-
public abstract IQuery CreateQuery(string category = null, BooleanOperation defaultOperation = BooleanOperation.And);
28+
public abstract IQuery CreateQuery(string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);
2929

3030
}
3131
}

src/Examine.Core/Examine.Core.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
66
<Description>Examine is an abstraction for indexing and search operations with implementations such as Lucene.Net</Description>
77
<PackageTags>examine search index</PackageTags>
8+
<Nullable>enable</Nullable>
9+
<LangVersion>9</LangVersion>
810
</PropertyGroup>
911

1012
<ItemGroup>

src/Examine.Core/ExamineExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static T GetNamedOptions<T>(this IOptionsMonitor<T> optionsMonitor, strin
2929
/// <returns></returns>
3030
public static IIndex GetIndex(this IExamineManager examineManager, string indexName)
3131
{
32-
if (examineManager.TryGetIndex(indexName, out IIndex index))
32+
if (examineManager.TryGetIndex(indexName, out IIndex? index))
3333
{
3434
return index;
3535
}

src/Examine.Core/ExamineManager.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4+
using System.Diagnostics.CodeAnalysis;
45
using System.Linq;
56

67
namespace Examine
@@ -27,11 +28,19 @@ public ExamineManager(IEnumerable<IIndex> indexes, IEnumerable<ISearcher> search
2728
private readonly ConcurrentDictionary<string, ISearcher> _searchers = new ConcurrentDictionary<string, ISearcher>(StringComparer.InvariantCultureIgnoreCase);
2829

2930
/// <inheritdoc />
30-
public bool TryGetSearcher(string searcherName, out ISearcher searcher) =>
31+
public bool TryGetSearcher(string searcherName,
32+
#if !NETSTANDARD2_0
33+
[MaybeNullWhen(false)]
34+
#endif
35+
out ISearcher searcher) =>
3136
(searcher = _searchers.TryGetValue(searcherName, out var s) ? s : null) != null;
3237

3338
/// <inheritdoc />
34-
public bool TryGetIndex(string indexName, out IIndex index) =>
39+
public bool TryGetIndex(string indexName,
40+
#if !NETSTANDARD2_0
41+
[MaybeNullWhen(false)]
42+
#endif
43+
out IIndex index) =>
3544
(index = _indexers.TryGetValue(indexName, out var i) ? i : null) != null;
3645

3746
/// <inheritdoc />

src/Examine.Core/FieldDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public FieldDefinition(string name, string type)
3232

3333
public bool Equals(FieldDefinition other) => string.Equals(Name, other.Name) && string.Equals(Type, other.Type);
3434

35-
public override bool Equals(object obj)
35+
public override bool Equals(object? obj)
3636
{
3737
if (ReferenceEquals(null, obj)) return false;
3838
return obj is FieldDefinition definition && Equals(definition);

src/Examine.Core/IExamineManager.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Linq;
34

45
namespace Examine
@@ -29,7 +30,11 @@ public interface IExamineManager
2930
/// <param name="indexName"></param>
3031
/// <param name="index"></param>
3132
/// <returns>true if the index was found by name</returns>
32-
bool TryGetIndex(string indexName, out IIndex index);
33+
bool TryGetIndex(string indexName,
34+
#if !NETSTANDARD2_0
35+
[MaybeNullWhen(false)]
36+
#endif
37+
out IIndex index);
3338

3439
/// <summary>
3540
/// Returns a searcher that was registered with <see cref="AddSearcher"/> or via config
@@ -39,7 +44,11 @@ public interface IExamineManager
3944
/// <returns>
4045
/// true if the searcher was found by name
4146
/// </returns>
42-
bool TryGetSearcher(string searcherName, out ISearcher searcher);
47+
bool TryGetSearcher(string searcherName,
48+
#if !NETSTANDARD2_0
49+
[MaybeNullWhen(false)]
50+
#endif
51+
out ISearcher searcher);
4352

4453
}
4554
}

src/Examine.Core/ISearchResult.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22

33
namespace Examine
44
{
@@ -41,6 +41,6 @@ public interface ISearchResult
4141
/// </summary>
4242
/// <param name="key"></param>
4343
/// <returns></returns>
44-
string this[string key] { get; }
44+
string? this[string key] { get; }
4545
}
46-
}
46+
}

src/Examine.Core/ISearcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface ISearcher
1515
/// <param name="searchText">The search text or a native query</param>
1616
/// <param name="maxResults"></param>
1717
/// <returns>Search Results</returns>
18-
ISearchResults Search(string searchText, QueryOptions options = null);
18+
ISearchResults Search(string searchText, QueryOptions? options = null);
1919

2020
/// <summary>
2121
/// Creates a search criteria instance as required by the implementation
@@ -25,6 +25,6 @@ public interface ISearcher
2525
/// <returns>
2626
/// An instance of <see cref="IQueryExecutor"/>
2727
/// </returns>
28-
IQuery CreateQuery(string category = null, BooleanOperation defaultOperation = BooleanOperation.And);
28+
IQuery CreateQuery(string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);
2929
}
3030
}

src/Examine.Core/IndexOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public class IndexOptions
55
public IndexOptions() => FieldDefinitions = new FieldDefinitionCollection();
66

77
public FieldDefinitionCollection FieldDefinitions { get; set; }
8-
public IValueSetValidator Validator { get; set; }
8+
public IValueSetValidator? Validator { get; set; }
99
}
1010
}

src/Examine.Core/IndexingErrorEventArgs.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ namespace Examine
88
public class IndexingErrorEventArgs : EventArgs
99
{
1010

11-
public IndexingErrorEventArgs(IIndex index, string message, string itemId, Exception exception)
11+
public IndexingErrorEventArgs(IIndex index, string message, string? itemId, Exception? exception)
1212
{
1313
Index = index;
1414
ItemId = itemId;
1515
Message = message;
1616
Exception = exception;
1717
}
1818

19-
public Exception Exception { get; }
19+
public Exception? Exception { get; }
2020
public string Message { get; }
2121
public IIndex Index { get; }
22-
public string ItemId { get; }
22+
public string? ItemId { get; }
2323
}
2424
}

src/Examine.Core/OrderedDictionary.cs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Diagnostics.CodeAnalysis;
45
using System.Linq;
56

67
namespace Examine
@@ -10,7 +11,7 @@ namespace Examine
1011
/// </summary>
1112
/// <typeparam name="TKey"></typeparam>
1213
/// <typeparam name="TVal"></typeparam>
13-
public class OrderedDictionary<TKey, TVal> : KeyedCollection<TKey, KeyValuePair<TKey, TVal>>, IDictionary<TKey, TVal>, IReadOnlyDictionary<TKey, TVal>
14+
public class OrderedDictionary<TKey, TVal> : KeyedCollection<TKey, KeyValuePair<TKey, TVal>>, IDictionary<TKey, TVal>, IReadOnlyDictionary<TKey, TVal> where TKey : notnull
1415
{
1516
public OrderedDictionary()
1617
{
@@ -56,7 +57,14 @@ public void Add(TKey key, TVal value)
5657
base.Add(new KeyValuePair<TKey, TVal>(key, value));
5758
}
5859

59-
public bool TryGetValue(TKey key, out TVal value)
60+
#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
61+
// Justification for warning disabled: IDictionary is missing [MaybeNullWhen(false)] in Netstandard 2.1
62+
public bool TryGetValue(TKey key,
63+
#pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
64+
#if !NETSTANDARD2_0
65+
[MaybeNullWhen(false)]
66+
#endif
67+
out TVal value)
6068
{
6169
if (base.Dictionary == null)
6270
{
@@ -89,7 +97,7 @@ TVal IDictionary<TKey, TVal>.this[TKey key]
8997
{
9098
return found.Value;
9199
}
92-
return default(TVal);
100+
return default(TVal); // TODO: should this throw instead
93101
}
94102
set
95103
{
@@ -113,4 +121,4 @@ TVal IDictionary<TKey, TVal>.this[TKey key]
113121

114122
public ICollection<TVal> Values => base.Dictionary != null ? base.Dictionary.Values.Select(x => x.Value).ToArray() : EmptyValues;
115123
}
116-
}
124+
}

src/Examine.Core/Search/FacetResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public IEnumerator<IFacetValue> GetEnumerator()
2121
return _values.GetEnumerator();
2222
}
2323

24-
public IFacetValue Facet(string label)
24+
public IFacetValue? Facet(string label)
2525
{
2626
return _values.FirstOrDefault(field => field.Label.Equals(label));
2727
}

src/Examine.Core/Search/IFacetResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public interface IFacetResult : IEnumerable<IFacetValue>
99
/// </summary>
1010
/// <param name="label"></param>
1111
/// <returns></returns>
12-
IFacetValue Facet(string label);
12+
IFacetValue? Facet(string label);
1313
}
1414
}

src/Examine.Core/Search/INestedQuery.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22

33
namespace Examine.Search
44
{
@@ -85,7 +85,7 @@ public interface INestedQuery
8585
/// <param name="query"></param>
8686
/// <param name="fields"></param>
8787
/// <returns></returns>
88-
INestedBooleanOperation ManagedQuery(string query, string[] fields = null);
88+
INestedBooleanOperation ManagedQuery(string query, string[]? fields = null);
8989

9090
/// <summary>
9191
/// Matches items as defined by the IIndexFieldValueType used for the fields specified.
@@ -100,4 +100,4 @@ public interface INestedQuery
100100
/// <returns></returns>
101101
INestedBooleanOperation RangeQuery<T>(string[] fields, T? min, T? max, bool minInclusive = true, bool maxInclusive = true) where T : struct;
102102
}
103-
}
103+
}

src/Examine.Core/Search/IQuery.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public interface IQuery
121121
/// <param name="query"></param>
122122
/// <param name="fields"></param>
123123
/// <returns></returns>
124-
IBooleanOperation ManagedQuery(string query, string[] fields = null);
124+
IBooleanOperation ManagedQuery(string query, string[]? fields = null);
125125

126126
/// <summary>
127127
/// Matches items as defined by the IIndexFieldValueType used for the fields specified.

src/Examine.Core/Search/IQueryExecutor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public interface IQueryExecutor
99
/// <summary>
1010
/// Executes the query
1111
/// </summary>
12-
ISearchResults Execute(QueryOptions options = null);
12+
ISearchResults Execute(QueryOptions? options = null);
1313
}
1414
}

src/Examine.Core/SearchResult.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.Specialized;
44
using System.Linq;
@@ -7,7 +7,7 @@ namespace Examine
77
{
88
public class SearchResult : ISearchResult
99
{
10-
private OrderedDictionary<string, string> _fields;
10+
private OrderedDictionary<string, string>? _fields;
1111
private readonly Lazy<OrderedDictionary<string, IReadOnlyList<string>>> _fieldValues;
1212

1313
/// <summary>
@@ -94,14 +94,14 @@ public IEnumerable<string> GetValues(string key)
9494
/// </summary>
9595
/// <param name="key"></param>
9696
/// <returns></returns>
97-
public string this[string key] => Values.TryGetValue(key, out var single) ? single : null;
97+
public string? this[string key] => Values.TryGetValue(key, out var single) ? single : null;
9898

9999
/// <summary>
100100
/// Override this method so that the Distinct() operator works
101101
/// </summary>
102102
/// <param name="obj"></param>
103103
/// <returns></returns>
104-
public override bool Equals(object obj)
104+
public override bool Equals(object? obj)
105105
{
106106
if (obj == null || GetType() != obj.GetType())
107107
return false;

0 commit comments

Comments
 (0)