Browse Source

Merge pull request #1987 from AvaloniaUI/refactor/use-netstandard2-apis

Use netstandard 2.0 APIs
pull/2037/head
danwalmsley 7 years ago
committed by GitHub
parent
commit
7c99404c32
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Avalonia.Base/Platform/IRuntimePlatform.cs
  2. 2
      src/Avalonia.Controls/AppBuilderBase.cs
  3. 4
      src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs
  4. 2
      src/Linux/Avalonia.LinuxFramebuffer/Mice.cs
  5. 4
      src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs
  6. 2
      src/Shared/PlatformSupport/AssetLoader.cs
  7. 4
      src/Shared/PlatformSupport/StandardRuntimePlatform.cs
  8. 3
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  9. 6
      src/Windows/Avalonia.Win32/Win32Platform.cs

3
src/Avalonia.Base/Platform/IRuntimePlatform.cs

@ -5,10 +5,7 @@ namespace Avalonia.Platform
{
public interface IRuntimePlatform
{
Assembly[] GetLoadedAssemblies();
void PostThreadPoolItem(Action cb);
IDisposable StartSystemTimer(TimeSpan interval, Action tick);
string GetStackTrace();
RuntimePlatformInfo GetRuntimeInfo();
IUnmanagedBlob AllocBlob(int size);
}

2
src/Avalonia.Controls/AppBuilderBase.cs

@ -222,7 +222,7 @@ namespace Avalonia.Controls
private void SetupAvaloniaModules()
{
var moduleInitializers = from assembly in AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetLoadedAssemblies()
var moduleInitializers = from assembly in AppDomain.CurrentDomain.GetAssemblies()
from attribute in assembly.GetCustomAttributes<ExportAvaloniaModuleAttribute>()
where attribute.ForWindowingSubsystem == ""
|| attribute.ForWindowingSubsystem == WindowingSubsystemName

4
src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs

@ -55,7 +55,7 @@ namespace Avalonia
LoadAssembliesInDirectory();
var windowingSubsystemAttribute = (from assembly in RuntimePlatform.GetLoadedAssemblies()
var windowingSubsystemAttribute = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
from attribute in assembly.GetCustomAttributes<ExportWindowingSubsystemAttribute>()
where attribute.RequiredOS == os && CheckEnvironment(attribute.EnvironmentChecker)
orderby attribute.Priority ascending
@ -65,7 +65,7 @@ namespace Avalonia
throw new InvalidOperationException("No windowing subsystem found. Are you missing assembly references?");
}
var renderingSubsystemAttribute = (from assembly in RuntimePlatform.GetLoadedAssemblies()
var renderingSubsystemAttribute = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
from attribute in assembly.GetCustomAttributes<ExportRenderingSubsystemAttribute>()
where attribute.RequiredOS == os && CheckEnvironment(attribute.EnvironmentChecker)
where attribute.RequiresWindowingSubsystem == null

2
src/Linux/Avalonia.LinuxFramebuffer/Mice.cs

@ -22,7 +22,7 @@ namespace Avalonia.LinuxFramebuffer
_height = height;
}
public void Start() => AvaloniaLocator.Current.GetService<IRuntimePlatform>().PostThreadPoolItem(Worker);
public void Start() => ThreadPool.UnsafeQueueUserWorkItem(_ => Worker(), null);
private void Worker()
{

4
src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs

@ -91,9 +91,7 @@ namespace Avalonia.Markup.Xaml.Context
private void ScanNewAssemblies()
{
IEnumerable<Assembly> assemblies = AvaloniaLocator.Current
.GetService<IRuntimePlatform>()
?.GetLoadedAssemblies();
IEnumerable<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies();
if (assemblies != null)
{

2
src/Shared/PlatformSupport/AssetLoader.cs

@ -157,7 +157,7 @@ namespace Avalonia.Shared.PlatformSupport
AssemblyDescriptor rv;
if (!AssemblyNameCache.TryGetValue(name, out rv))
{
var loadedAssemblies = AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetLoadedAssemblies();
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var match = loadedAssemblies.FirstOrDefault(a => a.GetName().Name == name);
if (match != null)
{

4
src/Shared/PlatformSupport/StandardRuntimePlatform.cs

@ -13,15 +13,11 @@ namespace Avalonia.Shared.PlatformSupport
{
internal partial class StandardRuntimePlatform : IRuntimePlatform
{
public void PostThreadPoolItem(Action cb) => ThreadPool.UnsafeQueueUserWorkItem(_ => cb(), null);
public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies();
public IDisposable StartSystemTimer(TimeSpan interval, Action tick)
{
return new Timer(_ => tick(), null, interval, interval);
}
public string GetStackTrace() => Environment.StackTrace;
public IUnmanagedBlob AllocBlob(int size) => new UnmanagedBlob(this, size);
class UnmanagedBlob : IUnmanagedBlob

3
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -756,9 +756,6 @@ namespace Avalonia.Win32.Interop
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll")]
public static extern uint GetCurrentThreadId();
[DllImport("user32.dll")]
public static extern int GetSystemMetrics(SystemMetric smIndex);

6
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -42,7 +42,7 @@ namespace Avalonia.Win32
class Win32Platform : IPlatformThreadingInterface, IPlatformSettings, IWindowingPlatform, IPlatformIconLoader
{
private static readonly Win32Platform s_instance = new Win32Platform();
private static uint _uiThread;
private static Thread _uiThread;
private UnmanagedMethods.WndProc _wndProcDelegate;
private IntPtr _hwnd;
private readonly List<Delegate> _delegates = new List<Delegate>();
@ -82,7 +82,7 @@ namespace Avalonia.Win32
.Bind<IPlatformIconLoader>().ToConstant(s_instance);
Win32GlManager.Initialize();
UseDeferredRendering = deferredRendering;
_uiThread = UnmanagedMethods.GetCurrentThreadId();
_uiThread = Thread.CurrentThread;
if (OleContext.Current != null)
AvaloniaLocator.CurrentMutable.Bind<IPlatformDragSource>().ToSingleton<DragSource>();
@ -146,7 +146,7 @@ namespace Avalonia.Win32
new IntPtr(SignalL));
}
public bool CurrentThreadIsLoopThread => _uiThread == UnmanagedMethods.GetCurrentThreadId();
public bool CurrentThreadIsLoopThread => _uiThread == Thread.CurrentThread;
public event Action<DispatcherPriority?> Signaled;

Loading…
Cancel
Save