See More

using System.Diagnostics; using System.Management; namespace BytecodeApi.Wmi; ///

/// Represents a WMI class. /// [DebuggerDisplay($"{nameof(WmiClass)}: Name = {{Name}}, Namespace = {{Namespace.FullPath}}")] public sealed class WmiClass : IWmiQueryable { /// /// Gets the associated with this . /// public WmiNamespace Namespace { get; } /// /// Gets the name of this . /// public string Name { get; } internal WmiClass(WmiNamespace @namespace, string name) { Namespace = @namespace; Name = name; } /// /// Specifies what columns to read from the WMI class. By default, all columns are read. /// /// A [] specifying what columns to read from the WMI class. /// /// The query with the additional SELECT statement. /// public IWmiQueryable Select(params string[] columns) { return new WmiQueryBuilder(this).Select(columns); } /// /// Specifies a filter condition for the WMI WHERE clause. /// /// A statement for the WMI WHERE clause. /// /// The query with the additional WHERE statement. /// public IWmiQueryable Where(string condition) { return new WmiQueryBuilder(this).Where(condition); } /// /// Executes this query and reads the contents from the WMI class. /// /// /// A new [] with the contents from the WMI class. /// public WmiObject[] ToArray() { return new WmiQueryBuilder(this).ToArray(); } /// /// Executes this query and reads the first element from the WMI class. /// /// /// A new with the first element from the WMI class. /// public WmiObject First() { return new WmiQueryBuilder(this).First(); } /// /// Executes this query and reads the first element from the WMI class, and returns , if the query returned no elements. /// /// /// A new with the first element from the WMI class, or , if the query returned no elements. /// public WmiObject? FirstOrDefault() { return new WmiQueryBuilder(this).FirstOrDefault(); } /// /// Invokes a method on this . /// /// The name of the method to invoke. /// An array containing parameter values. /// /// The value returned by the method. /// public object InvokeMethod(string methodName, params object[]? args) { Check.ArgumentNull(methodName); using ManagementClass managementClass = new(Namespace.FullPath, Name, new ObjectGetOptions()); return managementClass.InvokeMethod(methodName, args ?? []); } /// /// Invokes a method on this . /// /// The name of the method to invoke. /// An array containing parameter values. /// The type of the returned value. /// /// The value returned by the method, casted to . /// public T InvokeMethod(string methodName, params object[]? args) { return (T)InvokeMethod(methodName, args); } }