Пример #1
0
        private void btnAssemblyReflection_Click(object sender, RoutedEventArgs e)
        {
            var assemblyPath = txtAssemblyPath.Text;
            var manager      = new AssemblyReflectionManager();
            var success      = manager.LoadAssembly(assemblyPath, "VNCReflectionDomain");

            var results = manager.Reflect(assemblyPath, (a) =>
            {
                var names = new List <String>();
                var types = a.GetTypes();

                foreach (var t in types)
                {
                    names.Add(t.Name);
                }

                return(names);
            });

            txtOutput.Clear();

            foreach (var name in results)
            {
                txtOutput.Text += (System.Environment.NewLine + name.ToString());
            }

            manager.UnloadAssembly(assemblyPath);
        }
        public void ReflectShouldThrowArgumentExceptionOnUnknownAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentException>(() => tested.Reflect(GetType().Assembly.Location, a => a.FullName));
        }
        public void ReflectRequiresArgumentFunc()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentNullException>(() => tested.Reflect <int>(GetType().Assembly.Location, null));
        }
        public void ReflectRequiresArgumentAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentNullException>(() => tested.Reflect(null, a => a.FullName));
        }
        public bool Add(string assemblyPath)
        {
            if (assemblyPath == null)
            throw new ArgumentNullException("assemblyPath");

              FileInfo assemblyFile = new FileInfo(assemblyPath);
              if (!assemblyFile.Exists)
            throw new FileNotFoundException();

              try
              {
            using (AssemblyReflectionManager reflectionManager = new AssemblyReflectionManager())
            {
              lock (this.assemblyPaths)
              {
            if (this.pathAssembly.ContainsKey(assemblyPath))
              throw new ArgumentException(Resources.AssemblyAlreadyAdded);

            if (reflectionManager.LoadAssembly(assemblyFile.FullName))
            {
              var assemblyName = reflectionManager.Reflect(assemblyFile.FullName, assembly => assembly.FullName);
              AddPathToName(assemblyName, assemblyFile.FullName);

              this.log.Info(Resources.AssemblyAdded, assemblyFile.FullName);

              if (this.AssemblyAdded != null)
                this.AssemblyAdded(this, new AssemblyAddedEventArgs(assemblyFile.FullName, reflectionManager));

              return true;
            }
              }
            }
              }
              catch (BadImageFormatException) { }
              catch (FileLoadException) { }

              return false;
        }
 public void ReflectShouldThrowArgumentExceptionOnUnknownAssembly()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       DoAssert.Throws<ArgumentException>(() => tested.Reflect(GetType().Assembly.Location, a => a.FullName));
 }
 public void ReflectRequiresArgumentFunc()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       DoAssert.Throws<ArgumentNullException>(() => tested.Reflect<int>(GetType().Assembly.Location, null));
 }
 public void ReflectRequiresArgumentAssembly()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       DoAssert.Throws<ArgumentNullException>(() => tested.Reflect(null, a => a.FullName));
 }