コード例 #1
0
        private AssemblyDescriptor GetAssembly(string name)
        {
            if (name == null)
            {
                return(_defaultAssembly);
            }

            AssemblyDescriptor rv;

            if (!AssemblyNameCache.TryGetValue(name, out rv))
            {
                var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
                var match            = loadedAssemblies.FirstOrDefault(a => a.GetName().Name == name);
                if (match != null)
                {
                    AssemblyNameCache[name] = rv = new AssemblyDescriptor(match);
                }
                else
                {
                    // iOS does not support loading assemblies dynamically!
                    //
#if NETCOREAPP1_0
                    AssemblyNameCache[name] = rv = new AssemblyDescriptor(Assembly.Load(new AssemblyName(name)));
#elif __IOS__
                    throw new InvalidOperationException(
                              $"Assembly {name} needs to be referenced and explicitly loaded before loading resources");
#else
                    AssemblyNameCache[name] = rv = new AssemblyDescriptor(Assembly.Load(name));
#endif
                }
            }

            return(rv);
        }
コード例 #2
0
ファイル: AssetLoader.cs プロジェクト: sqdavid/Avalonia
        private AssemblyDescriptor GetAssembly(string name)
        {
            if (name == null)
            {
                return(_defaultAssembly);
            }

            AssemblyDescriptor rv;

            if (!AssemblyNameCache.TryGetValue(name, out rv))
            {
                var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
                var match            = loadedAssemblies.FirstOrDefault(a => a.GetName().Name == name);
                if (match != null)
                {
                    AssemblyNameCache[name] = rv = new AssemblyDescriptor(match);
                }
                else
                {
                    // iOS does not support loading assemblies dynamically!
                    //
#if !__IOS__
                    AssemblyNameCache[name] = rv = new AssemblyDescriptor(Assembly.Load(name));
#endif
                }
            }

            return(rv);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetLoader"/> class.
 /// </summary>
 /// <param name="assembly">
 /// The default assembly from which to load assets for which no assembly is specified.
 /// </param>
 public AssetLoader(Assembly assembly = null)
 {
     if (assembly == null)
     {
         assembly = Assembly.GetEntryAssembly();
     }
     if (assembly != null)
     {
         _defaultAssembly = new AssemblyDescriptor(assembly);
     }
 }
コード例 #4
0
 /// <summary>
 /// Sets the default assembly from which to load assets for which no assembly is specified.
 /// </summary>
 /// <param name="assembly">The default assembly.</param>
 public void SetDefaultAssembly(Assembly assembly)
 {
     _defaultAssembly = new AssemblyDescriptor(assembly);
 }