Exemplo n.º 1
0
        /// <summary>
        /// Get a reference to a type from a loaded assembly.
        /// </summary>
        /// <param name="fullName">The full name (namespace and class name) of the type.</param>
        /// <returns>Returns the type if it has been found. Otherwise, throws a <see cref="TypeLoadException"/>.<returns>
        public Type GetTypeRef(string fullName)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(FastReflection));
            }

            Requires.NotNull(_assemblySandbox, nameof(_assemblySandbox));

            return(_assemblySandbox.GetTypeRef(fullName));
        }
Exemplo n.º 2
0
        public void AssemblySandboxLoadType()
        {
            var sandbox1 = new AssemblySandbox();

            try
            {
                Type.GetType("System.Windows.UIElement", true, false);
                Assert.Fail();
            }
            catch (TypeLoadException)
            {
            }
            catch
            {
                Assert.Fail();
            }

            try
            {
                sandbox1.GetTypeRef("System.Windows.UIElement");
                Assert.Fail();
            }
            catch (TypeLoadException)
            {
            }
            catch
            {
                Assert.Fail();
            }

            sandbox1.LoadAssembly("PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

            try
            {
                Type.GetType("System.Windows.UIElement", true, false);
                Assert.Fail();
            }
            catch (TypeLoadException)
            {
            }
            catch
            {
                Assert.Fail();
            }

            Assert.AreEqual(1, sandbox1.GetAssemblies().Count);
            Assert.IsNotNull(sandbox1.GetTypeRef("System.Windows.UIElement", "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"));
            Assert.AreEqual(1, sandbox1.GetAssemblies().Count);
            Assert.IsNotNull(sandbox1.GetTypeRef("System.Windows.UIElement"));
            Assert.AreEqual(6, sandbox1.GetAssemblies().Count);

            sandbox1.Dispose();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates an instance of the compiled program class, if it is not already instanciated.
 /// </summary>
 private void InitializeProgram()
 {
     if (_compiledProgramInstance == null)
     {
         _compiledProgramInstance = _assemblySandbox.Reflection.Instantiate(_assemblySandbox.GetTypeRef(Consts.CompiledProgramClassName));
     }
 }