Exemplo n.º 1
0
        private static IPersistableImageFormat ExamineAssembly(Assembly assembly)
        {
            IPersistableImageFormat imageFormatPlugin = null;

            try
            {
                //Enumerate through the assembly object
                //
                foreach (Type testType in assembly.GetTypes())
                {
                    //Look for public types and ignore abstract classes
                    //
                    if (testType.IsPublic && testType.Attributes != TypeAttributes.Abstract)
                    {
                        if (testType.GetInterface(PluginInterfaceName, true) != null && testType.IsClass && !testType.IsAbstract)
                        {
                            object pluginObject = assembly.CreateInstance(testType.FullName);
                            imageFormatPlugin = (IPersistableImageFormat)pluginObject;
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException) { }
            catch (FileLoadException) { }
            return(imageFormatPlugin);
        }
        public static ImageOutputCollection Load()
        {
            ImageOutputCollection imageOutputCollection = new ImageOutputCollection();

            IPersistableImageFormat imageFormatPlugin = null;

            //DC load from current Dll
            var assembly = Assembly.GetExecutingAssembly();

            foreach (Type testType in assembly.GetTypes())
            {
                //Look for public types and ignore abstract classes

                if (testType.IsPublic && testType.Attributes != TypeAttributes.Abstract)
                {
                    //Does the type implement the proper interface
                    //
                    if ((testType.GetInterface(PluginInterfaceName, true)) != null && testType.IsClass && !testType.IsAbstract)
                    {
                        object pluginObject = assembly.CreateInstance(testType.FullName);
                        imageFormatPlugin = (IPersistableImageFormat)pluginObject;
                        imageOutputCollection.Add(imageFormatPlugin);
                    }
                }
            }


            /*
             *          foreach (string path in LoadValidAssemblies())
             *          {
             *                  try
             *                  {
             *                          Assembly assembly;
             *                          assembly = Assembly.LoadFrom(path);
             *                          IPersistableImageFormat imageFormatPlugin;
             *                          imageFormatPlugin = ExamineAssembly(assembly);
             *                          if (imageFormatPlugin != null)
             *                                  imageOutputCollection.Add(imageFormatPlugin);
             *                  }
             *                  catch (FileLoadException e)
             *                  {
             *                          Debug.WriteLine(e.Message);
             *                  }
             *          }*/
            return(imageOutputCollection);
        }
Exemplo n.º 3
0
        public static ImageOutputCollection Load()
        {
            ImageOutputCollection imageOutputCollection = new ImageOutputCollection();

            foreach (string path in LoadValidAssemblies())
            {
                try
                {
                    Assembly assembly = Assembly.LoadFrom(path);
                    IPersistableImageFormat imageFormatPlugin = ExamineAssembly(assembly);
                    if (imageFormatPlugin != null)
                    {
                        imageOutputCollection.Add(imageFormatPlugin);
                    }
                }
                catch (FileLoadException e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
            return(imageOutputCollection);
        }