Code cleanup

This commit is contained in:
2022-01-22 17:13:38 +03:00
parent 401f9fb529
commit ff63d6dfaa
13 changed files with 232 additions and 138 deletions
+7 -5
View File
@@ -1,4 +1,6 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -107,7 +109,7 @@ namespace Kruzya.TelegramBot.Core
/// </summary>
/// <param name="path">The full path to assembly file</param>
/// <returns><see cref="IEnumerable{T}"/> if success, null otherwise.</returns>
private IEnumerable<Type> LoadAssembly(string path)
private IEnumerable<Type>? LoadAssembly(string path)
{
Assembly assembly;
try
@@ -150,7 +152,7 @@ namespace Kruzya.TelegramBot.Core
var module = _modules.FirstOrDefault(module => module.GetType() == moduleType);
if (module == null)
{
module = (Module) Activator.CreateInstance(moduleType, this);
module = (Module) Activator.CreateInstance(moduleType, this)!;
Console.WriteLine($"Started module {module.GetType().Name}");
_modules.Add(module);
}
@@ -169,12 +171,12 @@ namespace Kruzya.TelegramBot.Core
var possiblePaths = new List<string>();
if (args.RequestingAssembly != null)
{
var modulePath = Path.GetDirectoryName(args.RequestingAssembly.Location);
var modulePath = Path.GetDirectoryName(args.RequestingAssembly.Location)!;
possiblePaths.Add(modulePath);
possiblePaths.Add(args.RequestingAssembly.Location.Replace(".dll", ""));
}
possiblePaths.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
possiblePaths.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!);
possiblePaths.Add(Environment.CurrentDirectory);
foreach (var basePath in possiblePaths)