/// <summary> /// 获取所有CPU信息列表 /// </summary> /// <returns></returns> public static IList <CpuInfo> GetCpuInfo() { ManagementClass managementClass = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = managementClass.GetInstances(); IList <CpuInfo> cpus = new List <CpuInfo>(); foreach (ManagementObject mo in moc) { CpuInfo cpu = new CpuInfo() { AddressWidth = CommOp.ToInt(mo.Properties["AddressWidth"]), CurrentClockSpeed = CommOp.ToInt(mo.Properties["CurrentClockSpeed"]), MaxClockSpeed = CommOp.ToInt(mo.Properties["MaxClockSpeed"]), Description = CommOp.ToStr(mo.Properties["Description"]), DeviceID = CommOp.ToStr(mo.Properties["DeviceID"]), ExtClock = CommOp.ToInt(mo.Properties["ExtClock"]), L2CacheSize = CommOp.ToInt(mo.Properties["L2CacheSize"]), Manufacturer = CommOp.ToStr(mo.Properties["Manufacturer"]), Name = CommOp.ToStr(mo.Properties["Name"]), ProcessorId = CommOp.ToStr(mo.Properties["ProcessorId"]), }; cpus.Add(cpu); } return(cpus); }
/// <summary> /// 将字符串分割成整数数组 /// </summary> /// <param name="ints"></param> /// <param name="c"></param> /// <returns></returns> public static int[] ToIntArray(string ints, char c) { if (ints.IsEmpty()) { return(new int[0]); } string[] sArr = ints.Split(c); int[] iArr = new int[sArr.Length]; for (int i = 0; i < iArr.Length; i++) { iArr[i] = CommOp.ToInt(sArr[i]); } return(iArr); }
/// <summary> /// 将reader[Key]转换为Int32 /// </summary> /// <param name="reader"></param> /// <param name="key"></param> /// <returns></returns> public static int ToInt(this IDataReader reader, string key) { return(CommOp.ToInt(reader[key])); }