public virtual Assembly[] GetAssemblies()
{
var options = new QueryOptions { FileTypeFilter = { ".exe", ".dll" } };
StorageFileQueryResult query = Package.Current.InstalledLocation.CreateFileQueryWithOptions(options);
IReadOnlyList<StorageFile> files = query.GetFilesAsync().AsTask().Result;
var assemblies = new List<Assembly>(files.Count);
foreach (StorageFile file in files)
{
try
{
Assembly assembly = Assembly.Load(new AssemblyName { Name = IOPath.GetFileNameWithoutExtension(file.Name) });
assemblies.Add(assembly);
}
catch (IOException)
{
}
catch (BadImageFormatException)
{
}
}
Assembly thisAssembly = GetType().GetTypeInfo().Assembly;
// this happens with .NET Native
if (!assemblies.Contains(thisAssembly))
assemblies.Add(thisAssembly);
Assembly coreAssembly = typeof(Xamarin.Forms.Label).GetTypeInfo().Assembly;
if (!assemblies.Contains(coreAssembly))
assemblies.Add(coreAssembly);
Assembly xamlAssembly = typeof(Xamarin.Forms.Xaml.Extensions).GetTypeInfo().Assembly;
if (!assemblies.Contains(xamlAssembly))
assemblies.Add(xamlAssembly);
return assemblies.ToArray();
}
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Xamarin.Forms.Platform.UAP
{
/// <summary>
/// Enables C++ code to simulate ICLRRuntimeHost2::ExecuteAssembly on top of ICLRRuntimeHost2::CreateDelegate in .net core 2.
/// </summary>
static class BootstrapHelper
{
// Do not overload this method. ICLRRuntimeHost2::CreateDelegate can not resolve overloaded methods.
[PreserveSig]
private static int Bootstrap(
[MarshalAs(UnmanagedType.LPWStr)] string assemblyPath,
[MarshalAs(UnmanagedType.LPWStr)] string typeName,
[MarshalAs(UnmanagedType.LPWStr)] string methodName,
[MarshalAs(UnmanagedType.LPWStr)] string argument)
{
try
{
MethodInfo loadFrom = typeof(Assembly).GetMethod("LoadFrom", new Type[] { typeof(string) });
if (loadFrom == null)
{
// LoadFrom is only available in .net core 2.0 and later. Since the target
// assembly isn't in the normal load path there isn't anything we can do.
throw new PlatformNotSupportedException();
}
Assembly assembly = (Assembly)loadFrom.Invoke(null, new object[] { assemblyPath });
Type type = assembly.GetType(typeName);
MethodInfo method = type.GetMethod(methodName);
method.Invoke(null, new object[] { argument });
return 0;
}
catch (Exception ex)
{
return ex.HResult;
}
}
}
}
public void Navigate(string uri)
{
Uri uriResult;
bool result = Uri.TryCreate(uri, UriKind.Absolute, out uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
if (result)
{
_browser.Navigate(new Uri(uri));
}
else
{
string appPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
string filePath = System.IO.Path.Combine(appPath, uri);
_browser.Url = new Uri(filePath);
}
}
static Assembly _assembly;
static Type FindType(string name, string altName)
{
return _assembly?.GetTypes().FirstOrDefault(x => x.Name == name || x.Name == altName);
}
static Type _drawableClass;
static Type _resourceClass;
static Type _styleClass;
static Type _layoutClass;
public static Type DrawableClass
{
get
{
if (_drawableClass == null)
_drawableClass = FindType("Drawable", "Resource_Drawable");
return _drawableClass;
}
set
{
_drawableClass = value;
}
}
public static Type ResourceClass
{
get
{
if (_resourceClass == null)
_resourceClass = FindType("Id", "Resource_Id");
return _resourceClass;
}
set
{
_resourceClass = value;
}
}
public static Type StyleClass
{
get
{
if (_styleClass == null)
_styleClass = FindType("Style", "Resource_Style");
return _styleClass;
}
set
{
_styleClass = value;
}
}
public static Type LayoutClass
{
get
{
if (_layoutClass == null)
_layoutClass = FindType("Layout", "Resource_Layout");
return _layoutClass;
}
set
{
_layoutClass = value;
}
}
cude cd
最新推荐文章于 2022-03-08 21:39:22 发布