static HardwareIdentifier() { #if NET5_0 if (OperatingSystem.IsWindows()) #endif theComputerCharacteristics = new WindowsComputerCharacteristics(); }
static HardwareIdentifier() { var interfaceType = typeof(IComputerCharacteristics); var currentAssembly = typeof(HardwareIdentifier).Assembly; var type = currentAssembly.GetTypes().Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass).FirstOrDefault(); if (type != null) { theComputerCharacteristics = (IComputerCharacteristics)Activator.CreateInstance(type); } }
/// <summary> /// Sets the <see cref="IComputerCharacteristics"/> implementation to use. /// </summary> /// <remarks> /// Not that the implementation depends on the actual OS. If no implementation is set, some methods like /// <see cref="ForCurrentComputer"/> and <see cref="IsValidForCurrentComputer(string)"/> throw an exception. /// </remarks> /// <param name="computerCharacteristics"> /// An implementation of <see cref="IComputerCharacteristics"/>. /// </param> public static void SetComputerCharacteristics(IComputerCharacteristics computerCharacteristics) { theComputerCharacteristics = computerCharacteristics; }