remove compat for netframework

This commit is contained in:
zznty
2022-06-05 15:43:15 +07:00
parent d2d96df8be
commit a1e9434444
7 changed files with 8 additions and 44 deletions

View File

@@ -1,8 +0,0 @@
#if NETFRAMEWORK
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;
public class IsExternalInit
{
}
#endif

View File

@@ -78,11 +78,7 @@ namespace Torch.API.WebAPI
if(File.Exists(path))
File.Delete(path);
#if NETFRAMEWORK
using var f = File.Create(path);
#else
await using var f = File.Create(path);
#endif
await s.CopyToAsync(f);
}
catch (Exception ex)

View File

@@ -40,13 +40,7 @@ namespace Torch.Server.Managers
protected abstract EntityControlViewModel Create(EntityViewModel evm);
#if NETFRAMEWORK
[ReflectedGetter(Name = "Keys")]
private static readonly Func<ConditionalWeakTable<EntityViewModel, EntityControlViewModel>, ICollection<EntityViewModel>> WeakTableKeys = null!;
internal IEnumerable<EntityViewModel> Keys => WeakTableKeys(_models);
#else
internal IEnumerable<EntityViewModel> Keys => _models.Select(b => b.Key);
#endif
internal EntityControlViewModel GetOrCreate(EntityViewModel evm)
{

View File

@@ -221,12 +221,10 @@ namespace Torch.Server
LogManager.Flush();
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
#if NETFRAMEWORK
config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
#else
config.WaitForPID = Environment.ProcessId.ToString();
#endif
config.TempAutostart = true;
Process.Start(exe, config.ToString());
Environment.Exit(0);
@@ -374,11 +372,8 @@ namespace Torch.Server
// return stack.ToString();
// Modified from https://www.examplefiles.net/cs/579311
#if NETFRAMEWORK
using var target = DataTarget.CreateSnapshotAndAttach(Process.GetCurrentProcess().Id);
#else
using var target = DataTarget.CreateSnapshotAndAttach(Environment.ProcessId);
#endif
var runtime = target.ClrVersions[0].CreateRuntime();
var clrThread = runtime.Threads.First(b => b.ManagedThreadId == thread.ManagedThreadId);

View File

@@ -32,11 +32,9 @@ internal class UnhandledExceptionHandler
Console.WriteLine("Restarting in 5 seconds.");
Thread.Sleep(5000);
var exe = typeof(Program).Assembly.Location;
#if NETFRAMEWORK
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
#else
_config.WaitForPID = Environment.ProcessId.ToString();
#endif
Process.Start(exe, _config.ToString());
}
else

View File

@@ -17,13 +17,8 @@ namespace Torch.Utils
try
{
var name = AssemblyName.GetAssemblyName(file);
var key = name.Name ?? name.FullName.Split(',')[0];
#if NETFRAMEWORK
if (!Assemblies.ContainsKey(key))
Assemblies.Add(key, file);
#else
var key = name.Name ?? name.FullName[..','];
Assemblies.TryAdd(key, file);
#endif
}
catch (BadImageFormatException)
{
@@ -37,7 +32,7 @@ namespace Torch.Utils
private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
var name = args.Name;
return Assemblies.TryGetValue(name.IndexOf(',') > 0 ? name.Substring(0, name.IndexOf(',')) : name, out var path) ? Assembly.LoadFrom(path) : null;
return Assemblies.TryGetValue(name.IndexOf(',') > 0 ? name[..','] : name, out var path) ? Assembly.LoadFrom(path) : null;
}
}
}

View File

@@ -13,9 +13,7 @@ namespace Torch.Utils;
public static class TorchLogManager
{
#if !NETFRAMEWORK
private static AssemblyLoadContext LoadContext = new("TorchLog");
#endif
private static readonly AssemblyLoadContext LoadContext = new("TorchLog");
public static LoggingConfiguration Configuration { get; private set; }
@@ -31,11 +29,7 @@ public static class TorchLogManager
if (!Directory.Exists(dir)) return;
foreach (var type in Directory.EnumerateFiles(dir, "*.dll")
#if NETFRAMEWORK
.Select(Assembly.LoadFile)
#else
.Select(LoadContext.LoadFromAssemblyPath)
#endif
.SelectMany(b => b.ExportedTypes)
.Where(b => b.GetCustomAttribute<TargetAttribute>() is { }))
{