diff --git a/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs b/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs index f219c45c..cd369772 100644 --- a/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs +++ b/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs @@ -30,62 +30,13 @@ namespace UniversalEditor.Common return a.Type.FullName.CompareTo(b.Type.FullName); } - private static Type[] mvarAvailableTypes = null; - public static Type[] GetAvailableTypes(Type[] inheritsFrom = null) - { - if (mvarAvailableTypes == null) - { - List types = new List(); - Assembly[] asms = GetAvailableAssemblies(); - for (int iAsm = 0; iAsm < asms.Length; iAsm++) - { - Assembly asm = asms[iAsm]; - Type[] types1 = null; - try - { - types1 = asm.GetTypes(); - } - catch (ReflectionTypeLoadException ex) - { - Console.Error.WriteLine("ReflectionTypeLoadException(" + ex.LoaderExceptions.Length.ToString() + "): " + asm.FullName); - Console.Error.WriteLine(ex.Message); - - types1 = ex.Types; - } - - if (types1 == null) continue; - - for (int jTyp = 0; jTyp < types1.Length; jTyp++) - { - if (types1[jTyp] == null) continue; - types.Add(types1[jTyp]); - } - } - mvarAvailableTypes = types.ToArray(); - } - - if (inheritsFrom != null) - { - List retval = new List(); - for (int iTyp = 0; iTyp < mvarAvailableTypes.Length; iTyp++) - { - for (int jInh = 0; jInh < inheritsFrom.Length; jInh++) - { - if (mvarAvailableTypes[iTyp].IsSubclassOf(inheritsFrom[jInh])) retval.Add(mvarAvailableTypes[iTyp]); - } - } - return retval.ToArray(); - } - return mvarAvailableTypes; - } - #region Initialization private static bool mvarInitialized = false; private static void Initialize() { if (mvarInitialized) return; - Type[] types = GetAvailableTypes(); + Type[] types = MBS.Framework.Reflection.GetAvailableTypes(); #region Initializing Object Models List listAccessors = new List(); @@ -636,48 +587,6 @@ namespace UniversalEditor.Common return null; } #endregion - #region Assemblies - private static Assembly[] mvarAvailableAssemblies = null; - public static Assembly[] GetAvailableAssemblies() - { - if (mvarAvailableAssemblies == null) - { - List list = new List(); - - List asmdirs = new List(); - string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); - asmdirs.Add(dir); - asmdirs.Add(dir + System.IO.Path.DirectorySeparatorChar.ToString() + "Plugins"); - - foreach (string asmdir in asmdirs) - { - if (!System.IO.Directory.Exists(asmdir)) continue; - - string[] FileNamesEXE = System.IO.Directory.GetFiles(asmdir, "*.exe", System.IO.SearchOption.TopDirectoryOnly); - string[] FileNamesDLL = System.IO.Directory.GetFiles(asmdir, "*.dll", System.IO.SearchOption.TopDirectoryOnly); - - string[] FileNames = new string[FileNamesEXE.Length + FileNamesDLL.Length]; - Array.Copy(FileNamesEXE, 0, FileNames, 0, FileNamesEXE.Length); - Array.Copy(FileNamesDLL, 0, FileNames, FileNamesEXE.Length, FileNamesDLL.Length); - - foreach (string FileName in FileNames) - { - try - { - Assembly asm = Assembly.LoadFile(FileName); - list.Add(asm); - } - catch - { - } - } - } - - mvarAvailableAssemblies = list.ToArray(); - } - return mvarAvailableAssemblies; - } - #endregion private static DocumentTemplate[] mvarAvailableDocumentTemplates = null; public static DocumentTemplate[] GetAvailableDocumentTemplates() diff --git a/CSharp/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs b/CSharp/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs index 14339338..550533f3 100644 --- a/CSharp/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs +++ b/CSharp/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs @@ -945,7 +945,7 @@ namespace UniversalEditor.DataFormats.UEPackage { CustomOption co = null; - Type[] tCustomOptions = UniversalEditor.Common.Reflection.GetAvailableTypes(new Type[] { typeof(CustomOption) }); + Type[] tCustomOptions = MBS.Framework.Reflection.GetAvailableTypes(new Type[] { typeof(CustomOption) }); foreach (Type tCustomOption in tCustomOptions) { if (tCustomOption.Name == tag.FullName) diff --git a/CSharp/Libraries/UniversalEditor.Essential/ProjectTaskAction.cs b/CSharp/Libraries/UniversalEditor.Essential/ProjectTaskAction.cs index a21703c2..f347f719 100644 --- a/CSharp/Libraries/UniversalEditor.Essential/ProjectTaskAction.cs +++ b/CSharp/Libraries/UniversalEditor.Essential/ProjectTaskAction.cs @@ -85,10 +85,10 @@ namespace UniversalEditor if (_dict == null) { _dict = new Dictionary(); - Type[] types = Common.Reflection.GetAvailableTypes(); + Type[] types = MBS.Framework.Reflection.GetAvailableTypes(new Type[] { typeof(ProjectTaskAction) }); foreach (Type type in types) { - if (!type.IsAbstract && type.IsSubclassOf(typeof(ProjectTaskAction))) + if (!type.IsAbstract) { ProjectTaskAction action = (ProjectTaskAction)type.Assembly.CreateInstance(type.FullName); ProjectTaskActionReference actionref = action.MakeReference(); diff --git a/CSharp/Libraries/UniversalEditor.Printing/Reflection.cs b/CSharp/Libraries/UniversalEditor.Printing/Reflection.cs index 6c498dbb..8fd6fa21 100644 --- a/CSharp/Libraries/UniversalEditor.Printing/Reflection.cs +++ b/CSharp/Libraries/UniversalEditor.Printing/Reflection.cs @@ -30,8 +30,23 @@ namespace UniversalEditor.Printing public static PrintHandlerReference[] GetAvailablePrintHandlers() { if (_phrs == null) - Initialize(); + { + List list = new List(); + Type[] types = MBS.Framework.Reflection.GetAvailableTypes(new Type[] { typeof(PrintHandler) }); + foreach (Type type in types) + { + if (type == null) continue; + if (type.IsSubclassOf(typeof(PrintHandler))) + { + PrintHandler ph = (type.Assembly.CreateInstance(type.FullName) as PrintHandler); + PrintHandlerReference phr = ph.MakeReference(); + + list.Add(phr); + } + } + _phrs = list.ToArray(); + } return _phrs; } @@ -46,41 +61,5 @@ namespace UniversalEditor.Printing } return list.ToArray(); } - - private static Assembly[] _asms = null; - private static void Initialize() - { - if (_asms == null) - { - List list = new List(); - _asms = UniversalEditor.Common.Reflection.GetAvailableAssemblies(); - foreach (Assembly asm in _asms) - { - Type[] types = null; - try - { - types = asm.GetTypes(); - } - catch (ReflectionTypeLoadException ex) - { - types = ex.Types; - } - - foreach (Type type in types) - { - if (type == null) continue; - - if (type.IsSubclassOf(typeof(PrintHandler))) - { - PrintHandler ph = (type.Assembly.CreateInstance(type.FullName) as PrintHandler); - PrintHandlerReference phr = ph.MakeReference(); - - list.Add(phr); - } - } - } - _phrs = list.ToArray(); - } - } } } diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs index 312a5c1b..ef56aec6 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs @@ -12,60 +12,44 @@ namespace UniversalEditor.UserInterface.Common { private static void Initialize() { - System.Reflection.Assembly[] asms = UniversalEditor.Common.Reflection.GetAvailableAssemblies(); - List listEditors = new List(); if (mvarAvailableEditors == null) { - foreach (System.Reflection.Assembly asm in asms) + Type[] types = MBS.Framework.Reflection.GetAvailableTypes(new Type[] { typeof(Editor) }); + + foreach (Type type in types) { - Type[] types = null; - try + if (type == null) continue; + + if (type.IsSubclassOf(typeof(Editor))) { - types = asm.GetTypes(); - } - catch (System.Reflection.ReflectionTypeLoadException ex) - { - Console.Error.WriteLine("ReflectionTypeLoadException(" + ex.LoaderExceptions.Length.ToString() + "): " + asm.FullName); - Console.Error.WriteLine(ex.Message); + #region Initializing Editors + Console.Write("loading editor '" + type.FullName + "'... "); - types = ex.Types; - } - - foreach (Type type in types) - { - if (type == null) continue; - - if (type.IsSubclassOf(typeof(Editor))) + try { - #region Initializing Editors - Console.Write("loading editor '" + type.FullName + "'... "); + // TODO: see if there is a way we can MakeReference() without having to create all the UI + // components of the IEditorImplementation + Editor editor = (type.Assembly.CreateInstance(type.FullName) as Editor); + listEditors.Add(editor.MakeReference()); - try - { - // TODO: see if there is a way we can MakeReference() without having to create all the UI - // components of the IEditorImplementation - Editor editor = (type.Assembly.CreateInstance(type.FullName) as Editor); - listEditors.Add(editor.MakeReference()); - - Console.WriteLine("SUCCESS!"); - } - catch (System.Reflection.TargetInvocationException ex) - { - Console.WriteLine("FAILURE!"); - - Console.WriteLine("binding error: " + ex.InnerException.Message); - } - catch (Exception ex) - { - Console.WriteLine("FAILURE!"); - - Console.WriteLine("error while loading editor '" + type.FullName + "': " + ex.Message); - } + Console.WriteLine("SUCCESS!"); + } + catch (System.Reflection.TargetInvocationException ex) + { + Console.WriteLine("FAILURE!"); + + Console.WriteLine("binding error: " + ex.InnerException.Message); + } + catch (Exception ex) + { + Console.WriteLine("FAILURE!"); + + Console.WriteLine("error while loading editor '" + type.FullName + "': " + ex.Message); } - #endregion } + #endregion } }