/// <summary> /// Initialize default values for private static fields. /// </summary> /// <remarks> /// <para> /// Only static methods are exposed from this type. /// </para> /// </remarks> static SystemInfo() { string nullText = DEFAULT_NULL_TEXT; string notAvailableText = DEFAULT_NOT_AVAILABLE_TEXT; #if !NETCF // Look for Library.Logging.NullText in AppSettings string nullTextAppSettingsKey = SystemInfo.GetAppSetting("Library.Logging.NullText"); if (nullTextAppSettingsKey != null && nullTextAppSettingsKey.Length > 0) { LogLog.Trace("SystemInfo: Initializing NullText value to [" + nullTextAppSettingsKey + "]."); nullText = nullTextAppSettingsKey; } // Look for Library.Logging.NotAvailableText in AppSettings string notAvailableTextAppSettingsKey = SystemInfo.GetAppSetting("Library.Logging.NotAvailableText"); if (notAvailableTextAppSettingsKey != null && notAvailableTextAppSettingsKey.Length > 0) { LogLog.Trace("SystemInfo: Initializing NotAvailableText value to [" + notAvailableTextAppSettingsKey + "]."); notAvailableText = notAvailableTextAppSettingsKey; } #endif s_notAvailableText = notAvailableText; s_nullText = nullText; }
/// <summary> /// Process a parsed converter pattern /// </summary> /// <param name="converterName">the name of the converter</param> /// <param name="option">the optional option for the converter</param> /// <param name="formattingInfo">the formatting info for the converter</param> private void ProcessConverter(string converterName, string option, FormattingInfo formattingInfo) { LogLog.Trace("PatternParser: Converter [" + converterName + "] Option [" + option + "] Format [min=" + formattingInfo.Min + ",max=" + formattingInfo.Max + ",leftAlign=" + formattingInfo.LeftAlign + "]"); // Lookup the converter type Type converterType = (Type)m_patternConverters[converterName]; if (converterType == null) { LogLog.Error("PatternParser: Unknown converter name [" + converterName + "] in conversion pattern."); } else { // Create the pattern converter PatternConverter pc = null; try { pc = (PatternConverter)Activator.CreateInstance(converterType); // formattingInfo variable is an instance variable, occasionally reset // and used over and over again pc.FormattingInfo = formattingInfo; pc.Option = option; IOptionHandler optionHandler = pc as IOptionHandler; if (optionHandler != null) { optionHandler.ActivateOptions(); } AddConverter(pc); } catch (Exception createInstanceEx) { LogLog.Error("PatternParser: Failed to create instance of Type [" + converterType.FullName + "] using default constructor. Exception: " + createInstanceEx.ToString()); } } }
/// <summary> /// Loads the type specified in the type string. /// </summary> /// <param name="relativeAssembly">An assembly to load the type from.</param> /// <param name="typeName">The name of the type to load.</param> /// <param name="throwOnError">Flag set to <c>true</c> to throw an exception if the type cannot be loaded.</param> /// <param name="ignoreCase"><c>true</c> to ignore the case of the type name; otherwise, <c>false</c></param> /// <returns>The type loaded or <c>null</c> if it could not be loaded.</returns> /// <remarks> /// <para> /// If the type name is fully qualified, i.e. if contains an assembly name in /// the type name, the type will be loaded from the system using /// <see cref="Type.GetType(string,bool)"/>. /// </para> /// <para> /// If the type name is not fully qualified it will be loaded from the specified /// assembly. If the type is not found in the assembly then all the loaded assemblies /// will be searched for the type. /// </para> /// </remarks> public static Type GetTypeFromString(Assembly relativeAssembly, string typeName, bool throwOnError, bool ignoreCase) { // Check if the type name specifies the assembly name if (typeName.IndexOf(',') == -1) { //LogLog.Trace("SystemInfo: Loading type ["+typeName+"] from assembly ["+relativeAssembly.FullName+"]"); #if NETCF return(relativeAssembly.GetType(typeName, throwOnError)); #else // Attempt to lookup the type from the relativeAssembly Type type = relativeAssembly.GetType(typeName, false, ignoreCase); if (type != null) { // Found type in relative assembly //LogLog.Trace("SystemInfo: Loaded type ["+typeName+"] from assembly ["+relativeAssembly.FullName+"]"); return(type); } Assembly[] loadedAssemblies = null; try { loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); } catch (System.Security.SecurityException ex) { // Insufficient permissions to get the list of loaded assemblies LogLog.Warn("Insufficient permissions to get the list of loaded assemblies: " + ex.Message); } if (loadedAssemblies != null) { // Search the loaded assemblies for the type foreach (Assembly assembly in loadedAssemblies) { type = assembly.GetType(typeName, false, ignoreCase); if (type != null) { // Found type in loaded assembly LogLog.Trace("SystemInfo: Loaded type [" + typeName + "] from assembly [" + assembly.FullName + "] by searching loaded assemblies."); return(type); } } } // Didn't find the type if (throwOnError) { throw new TypeLoadException("Could not load type [" + typeName + "]. Tried assembly [" + relativeAssembly.FullName + "] and all loaded assemblies"); } return(null); #endif } else { // Includes explicit assembly name //LogLog.Trace("SystemInfo: Loading type ["+typeName+"] from global Type"); #if NETCF return(Type.GetType(typeName, throwOnError)); #else return(Type.GetType(typeName, throwOnError, ignoreCase)); #endif } }