зеркало из https://github.com/AvaloniaUI/Avalonia.git
Use AppDomain.GetLoadedAssemblies() for all platforms
This commit is contained in:
Родитель
7a01250352
Коммит
0977161413
|
@ -1,6 +1,4 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Threading.ThreadPool" Version="4.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
|
||||
namespace Avalonia.Shared.PlatformSupport
|
||||
{
|
||||
internal partial class StandardRuntimePlatform
|
||||
{
|
||||
private static readonly Lazy<Assembly[]> Assemblies = new Lazy<Assembly[]>(LoadAssemblies);
|
||||
public Assembly[] GetLoadedAssemblies() => Assemblies.Value;
|
||||
|
||||
static Assembly[] LoadAssemblies()
|
||||
{
|
||||
var assemblies = new List<Assembly>();
|
||||
// Mostly copy-pasted from (MIT):
|
||||
// https://github.com/StefH/System.AppDomain.Core/blob/0b35e676c2721aa367b96e62eb52c97ee0b43a70/src/System.AppDomain.NetCoreApp/AppDomain.cs
|
||||
|
||||
foreach (var assemblyName in
|
||||
DependencyContext.Default.GetRuntimeAssemblyNames(RuntimeEnvironment.GetRuntimeIdentifier()))
|
||||
{
|
||||
try
|
||||
{
|
||||
var assembly = Assembly.Load(assemblyName);
|
||||
// just load all types and skip this assembly if one or more types cannot be resolved
|
||||
assembly.DefinedTypes.ToArray();
|
||||
assemblies.Add(assembly);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.Write(ex.Message);
|
||||
}
|
||||
}
|
||||
return assemblies.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,13 +11,8 @@ namespace Avalonia.Shared.PlatformSupport
|
|||
{
|
||||
internal partial class StandardRuntimePlatform : IRuntimePlatform
|
||||
{
|
||||
|
||||
#if NETCOREAPP2_0
|
||||
public void PostThreadPoolItem(Action cb) => ThreadPool.QueueUserWorkItem(_ => cb(), null);
|
||||
#else
|
||||
public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies();
|
||||
public void PostThreadPoolItem(Action cb) => ThreadPool.UnsafeQueueUserWorkItem(_ => cb(), null);
|
||||
#endif
|
||||
public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies();
|
||||
public IDisposable StartSystemTimer(TimeSpan interval, Action tick)
|
||||
{
|
||||
return new Timer(_ => tick(), null, interval, interval);
|
||||
|
|
Загрузка…
Ссылка в новой задаче