Class SystemInfo
Utility class for system specific information.
public sealed class SystemInfo
- Inheritance
-
SystemInfo
- Inherited Members
Remarks
Utility class of static methods for system specific information.
Fields
EmptyTypes
Gets an empty array of types.
public static readonly Type[] EmptyTypes
Field Value
- Type[]
Remarks
The Type.EmptyTypes field is not available on
the .NET Compact Framework 1.0.
Properties
ApplicationBaseDirectory
Gets the base directory for this AppDomain.
public static string ApplicationBaseDirectory { get; }
Property Value
Remarks
Gets the base directory for this AppDomain.
The value returned may be either a local file path or a URI.
ApplicationFriendlyName
Get this application's friendly name
public static string ApplicationFriendlyName { get; }
Property Value
- string
The friendly name of this application as a string
Remarks
If available the name of the application is retrieved from
the AppDomain using AppDomain.CurrentDomain.FriendlyName.
Otherwise the file name of the entry assembly is used.
ConfigurationFileLocation
Gets the path to the configuration file for the current AppDomain.
public static string ConfigurationFileLocation { get; }
Property Value
Remarks
The .NET Compact Framework 1.0 does not have a concept of a configuration file. For this runtime, we use the entry assembly location as the root for the configuration file name.
The value returned may be either a local file path or a URI.
CurrentThreadId
Gets the ID of the current thread.
public static int CurrentThreadId { get; }
Property Value
- int
The ID of the current thread.
Remarks
On the .NET framework, the AppDomain.GetCurrentThreadId method
is used to obtain the thread ID for the current thread. This is the
operating system ID for the thread.
On the .NET Compact Framework 1.0 it is not possible to get the
operating system thread ID for the current thread. The native method
GetCurrentThreadId is implemented inline in a header file
and cannot be called.
On the .NET Framework 2.0 the Thread.ManagedThreadId is used as this
gives a stable id unrelated to the operating system thread ID which may
change if the runtime is using fibers.
EntryAssemblyLocation
Gets the path to the file that first executed in the current AppDomain.
public static string EntryAssemblyLocation { get; }
Property Value
- string
The path to the entry assembly.
Remarks
Gets the path to the file that first executed in the current AppDomain.
HostName
Get the host name or machine name for the current machine
public static string HostName { get; }
Property Value
- string
The hostname or machine name
Remarks
Get the host name or machine name for the current machine
The host name (GetHostName()) or
the machine name (Environment.MachineName) for
the current machine, or if neither of these are available
then NOT AVAILABLE is returned.
NewLine
Gets the system dependent line terminator.
public static string NewLine { get; }
Property Value
- string
The system dependent line terminator.
Remarks
Gets the system dependent line terminator.
NotAvailableText
Text to output when an unsupported feature is requested.
public static string NotAvailableText { get; set; }
Property Value
Remarks
Use this value when an unsupported feature is requested.
The default value is NOT AVAILABLE. This value can be overridden by specifying
a value for the log4net.NotAvailableText appSetting in the application's
.config file.
NullText
Text to output when a null is encountered.
public static string NullText { get; set; }
Property Value
Remarks
Use this value to indicate a null has been encountered while
outputting a string representation of an item.
The default value is (null). This value can be overridden by specifying
a value for the log4net.NullText appSetting in the application's
.config file.
ProcessStartTime
Get the start time for the current process.
public static DateTime ProcessStartTime { get; }
Property Value
Remarks
This is the time at which the log4net library was loaded into the
AppDomain. Due to reports of a hang in the call to System.Diagnostics.Process.StartTime
this is not the start time for the current process.
The log4net library should be loaded by an application early during its startup, therefore this start time should be a good approximation for the actual start time.
Note that AppDomains may be loaded and unloaded within the same process without the process terminating, however this start time will be set per AppDomain.
Methods
AssemblyFileName(Assembly)
Gets the file name portion of the Assembly, including the extension.
public static string AssemblyFileName(Assembly myAssembly)
Parameters
Returns
- string
The file name of the assembly.
Remarks
Gets the file name portion of the Assembly, including the extension.
AssemblyLocationInfo(Assembly)
Gets the assembly location path for the specified assembly.
public static string AssemblyLocationInfo(Assembly myAssembly)
Parameters
myAssemblyAssemblyThe assembly to get the location for.
Returns
- string
The location of the assembly.
Remarks
This method does not guarantee to return the correct path to the assembly. If only tries to give an indication as to where the assembly was loaded from.
AssemblyQualifiedName(Type)
Gets the fully qualified name of the Type, including the name of the assembly from which the Type was loaded.
public static string AssemblyQualifiedName(Type type)
Parameters
Returns
Remarks
This is equivalent to the Type.AssemblyQualifiedName property,
but this method works on the .NET Compact Framework 1.0 as well as
the full .NET runtime.
AssemblyShortName(Assembly)
Gets the short name of the Assembly.
public static string AssemblyShortName(Assembly myAssembly)
Parameters
Returns
Remarks
The short name of the assembly is the FullName without the version, culture, or public key. i.e. it is just the assembly's file name without the extension.
Use this rather than Assembly.GetName().Name because that
is not available on the Compact Framework.
Because of a FileIOPermission security demand we cannot do the obvious Assembly.GetName().Name. We are allowed to get the FullName of the assembly so we start from there and strip out just the assembly name.
ConvertToFullPath(string)
Convert a path into a fully qualified local file path.
public static string ConvertToFullPath(string path)
Parameters
pathstringThe path to convert.
Returns
- string
The fully qualified path.
Remarks
Converts the path specified to a fully qualified path. If the path is relative it is taken as relative from the application base directory.
The path specified must be a local file path, a URI is not supported.
CreateArgumentOutOfRangeException(string, object, string)
Create an ArgumentOutOfRangeException
public static ArgumentOutOfRangeException CreateArgumentOutOfRangeException(string parameterName, object actualValue, string message)
Parameters
parameterNamestringThe name of the parameter that caused the exception
actualValueobjectThe value of the argument that causes this exception
messagestringThe message that describes the error
Returns
- ArgumentOutOfRangeException
the ArgumentOutOfRangeException object
Remarks
Create a new instance of the ArgumentOutOfRangeException class with a specified error message, the parameter name, and the value of the argument.
The Compact Framework does not support the 3 parameter constructor for the ArgumentOutOfRangeException type. This method provides an implementation that works for all platforms.
CreateCaseInsensitiveHashtable()
Creates a new case-insensitive instance of the Hashtable class with the default initial capacity.
public static Hashtable CreateCaseInsensitiveHashtable()
Returns
Remarks
The new Hashtable instance uses the default load factor, the CaseInsensitiveHashCodeProvider, and the CaseInsensitiveComparer.
GetAppSetting(string)
Lookup an application setting
public static string GetAppSetting(string key)
Parameters
keystringthe application settings key to lookup
Returns
- string
the value for the key, or
null
Remarks
Configuration APIs are not supported under the Compact Framework
GetTypeFromString(Assembly, string, bool, bool)
Loads the type specified in the type string.
public static Type GetTypeFromString(Assembly relativeAssembly, string typeName, bool throwOnError, bool ignoreCase)
Parameters
relativeAssemblyAssemblyAn assembly to load the type from.
typeNamestringThe name of the type to load.
throwOnErrorboolFlag set to
trueto throw an exception if the type cannot be loaded.ignoreCasebooltrueto ignore the case of the type name; otherwise,false
Returns
- Type
The type loaded or
nullif it could not be loaded.
Remarks
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 Type.GetType(string,bool).
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.
GetTypeFromString(string, bool, bool)
Loads the type specified in the type string.
public static Type GetTypeFromString(string typeName, bool throwOnError, bool ignoreCase)
Parameters
typeNamestringThe name of the type to load.
throwOnErrorboolFlag set to
trueto throw an exception if the type cannot be loaded.ignoreCasebooltrueto ignore the case of the type name; otherwise,false
Returns
- Type
The type loaded or
nullif it could not be loaded.
Remarks
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 Type.GetType(string,bool).
If the type name is not fully qualified it will be loaded from the assembly that is directly calling this method. If the type is not found in the assembly then all the loaded assemblies will be searched for the type.
GetTypeFromString(Type, string, bool, bool)
Loads the type specified in the type string.
public static Type GetTypeFromString(Type relativeType, string typeName, bool throwOnError, bool ignoreCase)
Parameters
relativeTypeTypeA sibling type to use to load the type.
typeNamestringThe name of the type to load.
throwOnErrorboolFlag set to
trueto throw an exception if the type cannot be loaded.ignoreCasebooltrueto ignore the case of the type name; otherwise,false
Returns
- Type
The type loaded or
nullif it could not be loaded.
Remarks
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 Type.GetType(string,bool).
If the type name is not fully qualified, it will be loaded from the assembly containing the specified relative type. If the type is not found in the assembly then all the loaded assemblies will be searched for the type.
NewGuid()
Generate a new guid
public static Guid NewGuid()
Returns
- Guid
A new Guid
Remarks
Generate a new guid
TryParse(string, out short)
Parse a string into an short value
public static bool TryParse(string s, out short val)
Parameters
Returns
- bool
trueif the string was able to be parsed into an integer
Remarks
Attempts to parse the string into an integer. If the string cannot
be parsed then this method returns false. The method does not throw an exception.
TryParse(string, out int)
Parse a string into an int value
public static bool TryParse(string s, out int val)
Parameters
Returns
- bool
trueif the string was able to be parsed into an integer
Remarks
Attempts to parse the string into an integer. If the string cannot
be parsed then this method returns false. The method does not throw an exception.
TryParse(string, out long)
Parse a string into an long value
public static bool TryParse(string s, out long val)
Parameters
Returns
- bool
trueif the string was able to be parsed into an integer
Remarks
Attempts to parse the string into an integer. If the string cannot
be parsed then this method returns false. The method does not throw an exception.