The following example shows how to use the Enumerator attribute to mark a method that is used to enumerate instances of a class. In this case, the Enumerate method uses the Process class to retrieve all of the processes running on the computer.
[C#]
[ManagementEnumerator]
public static IEnumerable Enumerate()
{
Process[] rgProcesses = Process.GetProcesses();
for (int i = 0; i < rgProcesses.Length; i++)
{
yield return new ProcessProvider(rgProcesses[i]);
}
}