|
2 | 2 | using Types; |
3 | 3 | using Types.Base; |
4 | 4 |
|
| 5 | +/// <summary> |
| 6 | +/// Provides entry points for querying WMI (Windows Management Instrumentation) objects using strongly-typed LINQ queries. |
| 7 | +/// </summary> |
| 8 | +/// <remarks> |
| 9 | +/// <para> |
| 10 | +/// The <see cref="ManagementObjects"/> class enables LINQ-to-WQL queries over WMI classes, returning either strongly-typed objects or generic WMI objects. |
| 11 | +/// </para> |
| 12 | +/// <para> |
| 13 | +/// Use <see cref="Get{T}"/> for strongly-typed queries (e.g., <c>ManagementObjects.Get<Process>()</c>), or <see cref="Get(string)"/> for dynamic access by class name. |
| 14 | +/// </para> |
| 15 | +/// <para> |
| 16 | +/// Example usage: |
| 17 | +/// <code> |
| 18 | +/// using System.Management.Linq; |
| 19 | +/// using System.Management.Types.Win32; |
| 20 | +/// |
| 21 | +/// var processes = ManagementObjects.Get<Process>() |
| 22 | +/// .Where(p => p.Name == "explorer.exe") |
| 23 | +/// .ToList(); |
| 24 | +/// </code> |
| 25 | +/// </para> |
| 26 | +/// </remarks> |
5 | 27 | public static class ManagementObjects |
6 | 28 | { |
| 29 | + /// <summary> |
| 30 | + /// Returns a queryable sequence of strongly-typed WMI objects for the specified type <typeparamref name="T"/>. |
| 31 | + /// </summary> |
| 32 | + /// <typeparam name="T"> |
| 33 | + /// The target type representing a WMI class (e.g., <c>System.Management.Types.Win32.Process</c>). |
| 34 | + /// </typeparam> |
| 35 | + /// <returns> |
| 36 | + /// An <see cref="IQueryable{T}"/> for LINQ queries against the WMI class associated with <typeparamref name="T"/>. |
| 37 | + /// </returns> |
| 38 | + /// <exception cref="NotSupportedException"> |
| 39 | + /// Thrown if <typeparamref name="T"/> is not mapped to a WMI class. |
| 40 | + /// </exception> |
| 41 | + /// <remarks> |
| 42 | + /// The mapping between <typeparamref name="T"/> and the WMI class name is resolved via <see cref="InstanceFactory.GetClassNameOf{T}"/>. |
| 43 | + /// </remarks> |
7 | 44 | public static IQueryable<T> Get<T>() |
8 | 45 | => new ManagementObjectQueryable<T>(InstanceFactory.GetClassNameOf<T>() ?? throw new NotSupportedException($"Type {typeof(T).Name} is not supported by the {typeof(ManagementObjectQueryable<>)}.")); |
9 | 46 |
|
| 47 | + /// <summary> |
| 48 | + /// Returns a queryable sequence of generic WMI objects for the specified WMI class name. |
| 49 | + /// </summary> |
| 50 | + /// <param name="className">The WMI class name (e.g., <c>"Win32_Process"</c>).</param> |
| 51 | + /// <returns> |
| 52 | + /// An <see cref="IQueryable{_Object}"/> for LINQ queries against the specified WMI class. |
| 53 | + /// </returns> |
| 54 | + /// <remarks> |
| 55 | + /// Use this overload for dynamic or late-bound scenarios where a strongly-typed class is not available. |
| 56 | + /// </remarks> |
10 | 57 | public static IQueryable<_Object> Get(string className) |
11 | 58 | => new ManagementObjectQueryable<_Object>(className); |
12 | 59 | } |
0 commit comments