// Consolidated processing so we only have a single pass through the types. // CONSIDER: This is pretty ugly right now (both the flow and the names.) // Try some fancy visitor pattern? public static void ProcessAssemblies( List <ExportedAssembly> assemblies, List <MethodInfo> methods, List <ExcelAddInInfo> addIns, List <Type> rtdServerTypes, List <ExcelComClassType> comClassTypes) { List <AssemblyLoaderExcelServer.ExcelServerInfo> excelServerInfos = new List <AssemblyLoaderExcelServer.ExcelServerInfo>(); bool loadRibbons = (ExcelDnaUtil.ExcelVersion >= 12.0); foreach (ExportedAssembly assembly in assemblies) { // Patch contributed by y_i on CodePlex: // http://stackoverflow.com/questions/11915389/assembly-gettypes-throwing-an-exception Type[] types; try { types = assembly.Assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { // From MSDN: // [...]contains the array of classes (Types property) that were defined in the module and were loaded. // The array can contain some null values. types = e.Types; } bool explicitExports = assembly.ExplicitExports; bool explicitRegistration = assembly.ExplicitRegistration; foreach (Type type in types) { if (type == null) { continue; // We might get nulls from ReflectionTypeLoadException above } try { object[] attribs = type.GetCustomAttributes(false); bool isRtdServer; if (!explicitRegistration) { GetExcelMethods(type, explicitExports, methods); } AssemblyLoaderExcelServer.GetExcelServerInfos(type, attribs, excelServerInfos); GetExcelAddIns(assembly, type, loadRibbons, addIns); GetRtdServerTypes(type, rtdServerTypes, out isRtdServer); GetComClassTypes(assembly, type, attribs, isRtdServer, comClassTypes); } catch (Exception e) { // TODO: This is unexpected - raise to LogDisplay? Debug.Print("Type {0} could not be analysed. Error: {1}", type.FullName, e.ToString()); } } } // Sigh. Excel server (service?) stuff is till ugly - but no reeal reason to remove it yet. AssemblyLoaderExcelServer.GetExcelServerMethods(excelServerInfos, methods); }
// Consolidated processing so we only have a single pass through the types. // CONSIDER: This is pretty ugly right now (both the flow and the names.) // Try some fancy visitor pattern? public static void ProcessAssemblies( List <ExportedAssembly> assemblies, List <MethodInfo> methods, List <ExcelAddInInfo> addIns, List <Type> rtdServerTypes, List <ExcelComClassType> comClassTypes) { List <AssemblyLoaderExcelServer.ExcelServerInfo> excelServerInfos = new List <AssemblyLoaderExcelServer.ExcelServerInfo>(); bool loadRibbons = (ExcelDnaUtil.ExcelVersion >= 12.0); foreach (ExportedAssembly assembly in assemblies) { Type[] types = assembly.Assembly.GetTypes(); bool explicitExports = assembly.ExplicitExports; foreach (Type type in types) { try { object[] attribs = type.GetCustomAttributes(false); bool isRtdServer; GetExcelMethods(type, explicitExports, methods); AssemblyLoaderExcelServer.GetExcelServerInfos(type, attribs, excelServerInfos); GetExcelAddIns(assembly, type, loadRibbons, addIns); GetRtdServerTypes(type, rtdServerTypes, out isRtdServer); GetComClassTypes(assembly, type, attribs, isRtdServer, comClassTypes); } catch (Exception e) { // TODO: This is unexpected - raise to LogDisplay? Debug.Print("Type {0} could not be analysed. Error: {1}", type.FullName, e.ToString()); } } } // Sigh. Excel server (service?) stuff is till ugly - but no reeal reason to remove it yet. AssemblyLoaderExcelServer.GetExcelServerMethods(excelServerInfos, methods); }
// We consolidate the TraceSources for both ExcelDna.Integration and ExcelDna.Loader under the Excel.Integration name // (since it is the public contract for ExcelDna). // For the first version we don't make separate TraceSources for each class, though in future we might specialize under // the ExcelDna.Integration namespace, so listening to ExcelDna.Integration* will be the forward-compatible pattern. // Consolidated processing so we only have a single pass through the types. // CONSIDER: This is pretty ugly right now (both the flow and the names.) // Try some fancy visitor pattern? public static void ProcessAssemblies( List <ExportedAssembly> assemblies, List <MethodInfo> methods, List <ExcelAddInInfo> addIns, List <Type> rtdServerTypes, List <ExcelComClassType> comClassTypes) { List <AssemblyLoaderExcelServer.ExcelServerInfo> excelServerInfos = new List <AssemblyLoaderExcelServer.ExcelServerInfo>(); bool loadRibbons = (ExcelDnaUtil.ExcelVersion >= 12.0); foreach (ExportedAssembly assembly in assemblies) { Logger.Initialization.Verbose("Processing assembly {0}. ExplicitExports {1}, ExplicitRegistration {2}, ComServer {3}, IsDynamic {4}", assembly.Assembly.FullName, assembly.ExplicitExports, assembly.ExplicitRegistration, assembly.ComServer, assembly.IsDynamic); // Patch contributed by y_i on CodePlex: // http://stackoverflow.com/questions/11915389/assembly-gettypes-throwing-an-exception Type[] types; try { // NOTE: The fact that NonPublic types are returned here, and processed as-if they were public // was a mistake. But it would be a serious breaking change to go back, so we'll leave it as is. types = assembly.Assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { // From MSDN: // [...]contains the array of classes (Types property) that were defined in the module and were loaded. // The array can contain some null values. types = e.Types; } bool explicitExports = assembly.ExplicitExports; bool explicitRegistration = assembly.ExplicitRegistration; foreach (Type type in types) { if (type == null) { continue; // We might get nulls from ReflectionTypeLoadException above } Logger.Initialization.Verbose("Processing type {0}", type.FullName); try { object[] attribs = type.GetCustomAttributes(false); bool isRtdServer; if (!explicitRegistration) { GetExcelMethods(type, explicitExports, methods); } AssemblyLoaderExcelServer.GetExcelServerInfos(type, attribs, excelServerInfos); GetExcelAddIns(assembly, type, loadRibbons, addIns); GetRtdServerTypes(type, rtdServerTypes, out isRtdServer); GetComClassTypes(assembly, type, attribs, isRtdServer, comClassTypes); } catch (Exception e) { Logger.Initialization.Warn("Type {0} could not be processed. Error: {1}", type.FullName, e.ToString()); } } } // Sigh. Excel server (service?) stuff is still ugly - but no real reason to remove it yet. AssemblyLoaderExcelServer.GetExcelServerMethods(excelServerInfos, methods); }