Skip to content

Commit fc3be76

Browse files
committed
Figure out last couple of nullability issues
1 parent 259a91d commit fc3be76

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

BinaryObjectScanner/FileType/Executable.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,15 @@ private static IEnumerable<T> InitCheckClasses<T>(Assembly assembly)
447447
{
448448
return assembly.GetTypes()?
449449
.Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)?
450+
#if NET48
450451
.Select(t => (T)Activator.CreateInstance(t))
452+
#else
453+
.Select(t => (T?)Activator.CreateInstance(t))
454+
#endif
451455
.Cast<T>() ?? Array.Empty<T>();
452456
}
453457

454-
#endregion
458+
#endregion
455459

456460
#region Helpers
457461

BinaryObjectScanner/Handler.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ internal static class Handler
1818
/// <summary>
1919
/// Cache for all IPathCheck types
2020
/// </summary>
21+
#if NET48
2122
public static IEnumerable<IPathCheck> PathCheckClasses
23+
#else
24+
public static IEnumerable<IPathCheck?> PathCheckClasses
25+
#endif
2226
{
2327
get
2428
{
@@ -39,7 +43,7 @@ public static IEnumerable<IPathCheck> PathCheckClasses
3943
#if NET48
4044
private static IEnumerable<IPathCheck> pathCheckClasses;
4145
#else
42-
private static IEnumerable<IPathCheck>? pathCheckClasses;
46+
private static IEnumerable<IPathCheck?>? pathCheckClasses;
4347
#endif
4448

4549
#endregion
@@ -67,7 +71,7 @@ public static ConcurrentDictionary<string, ConcurrentQueue<string>> HandlePathCh
6771
// Iterate through all checks
6872
Parallel.ForEach(PathCheckClasses, checkClass =>
6973
{
70-
var subProtections = checkClass.PerformCheck(path, files);
74+
var subProtections = checkClass?.PerformCheck(path, files);
7175
if (subProtections != null)
7276
AppendToDictionary(protections, path, subProtections);
7377
});
@@ -162,7 +166,7 @@ private static ConcurrentQueue<string> PerformCheck(this IPathCheck impl, string
162166
return null;
163167

164168
// Setup the output dictionary
165-
var protections = new ConcurrentQueue<string>();
169+
var protections = new ConcurrentQueue<string>();
166170

167171
// If we have a file path
168172
if (File.Exists(path))
@@ -191,18 +195,33 @@ private static ConcurrentQueue<string> PerformCheck(this IPathCheck impl, string
191195
/// <summary>
192196
/// Initialize all implementations of a type
193197
/// </summary>
198+
#if NET48
194199
private static IEnumerable<T> InitCheckClasses<T>()
195-
=> InitCheckClasses<T>(typeof(BinaryObjectScanner.Packer._DUMMY).Assembly)
196-
.Concat(InitCheckClasses<T>(typeof(BinaryObjectScanner.Protection._DUMMY).Assembly));
200+
#else
201+
private static IEnumerable<T?> InitCheckClasses<T>()
202+
#endif
203+
{
204+
return InitCheckClasses<T>(typeof(GameEngine._DUMMY).Assembly)
205+
.Concat(InitCheckClasses<T>(typeof(Packer._DUMMY).Assembly))
206+
.Concat(InitCheckClasses<T>(typeof(Protection._DUMMY).Assembly));
207+
}
197208

198209
/// <summary>
199210
/// Initialize all implementations of a type
200211
/// </summary>
212+
#if NET48
201213
private static IEnumerable<T> InitCheckClasses<T>(Assembly assembly)
214+
#else
215+
private static IEnumerable<T?> InitCheckClasses<T>(Assembly assembly)
216+
#endif
202217
{
203218
return assembly.GetTypes()?
204219
.Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)?
220+
#if NET48
205221
.Select(t => (T)Activator.CreateInstance(t)) ?? Array.Empty<T>();
222+
#else
223+
.Select(t => (T?)Activator.CreateInstance(t)) ?? Array.Empty<T>();
224+
#endif
206225
}
207226

208227
#endregion

0 commit comments

Comments
 (0)