More enumerator usage

This commit is contained in:
Travis Nickles 2019-02-16 02:50:53 -06:00
parent 3417c08a87
commit a9e7a3cb5b
3 changed files with 17 additions and 8 deletions

View File

@ -346,9 +346,12 @@ namespace DS4Windows
DS4LightBar.defaultLight = false;
//foreach (DS4Device device in devices)
for (int i = 0, devCount = devices.Count(); i < devCount; i++)
//for (int i = 0, devCount = devices.Count(); i < devCount; i++)
int i = 0;
for (var devEnum = devices.GetEnumerator(); devEnum.MoveNext(); i++)
{
DS4Device device = devices.ElementAt(i);
DS4Device device = devEnum.Current;
//DS4Device device = devices.ElementAt(i);
if (showlog)
LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
@ -561,9 +564,11 @@ namespace DS4Windows
DS4Devices.findControllers();
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
//foreach (DS4Device device in devices)
for (int i = 0, devlen = devices.Count(); i < devlen; i++)
//for (int i = 0, devlen = devices.Count(); i < devlen; i++)
for (var devEnum = devices.GetEnumerator(); devEnum.MoveNext();)
{
DS4Device device = devices.ElementAt(i);
DS4Device device = devEnum.Current;
//DS4Device device = devices.ElementAt(i);
if (device.isDisconnectingStatus())
continue;

View File

@ -3507,9 +3507,11 @@ namespace DS4Windows
linkedXdoc.AppendChild(Node);
Dictionary<string, string>.KeyCollection serials = linkedProfiles.Keys;
for (int i = 0, itemCount = linkedProfiles.Count; i < itemCount; i++)
//for (int i = 0, itemCount = linkedProfiles.Count; i < itemCount; i++)
for (var serialEnum = serials.GetEnumerator(); serialEnum.MoveNext();)
{
string serial = serials.ElementAt(i);
//string serial = serials.ElementAt(i);
string serial = serialEnum.Current;
string profile = linkedProfiles[serial];
XmlElement link = linkedXdoc.CreateElement("MAC" + serial);
link.InnerText = profile;

View File

@ -179,9 +179,11 @@ namespace DS4Windows
{
IEnumerable<DS4Device> devices = getDS4Controllers();
//foreach (DS4Device device in devices)
for (int i = 0, devCount = devices.Count(); i < devCount; i++)
//for (int i = 0, devCount = devices.Count(); i < devCount; i++)
for (var devEnum = devices.GetEnumerator(); devEnum.MoveNext();)
{
DS4Device device = devices.ElementAt(i);
DS4Device device = devEnum.Current;
//DS4Device device = devices.ElementAt(i);
device.StopUpdate();
//device.runRemoval();
device.HidDevice.CloseDevice();