Blip,
I would create a static method which would return IEnumerable<T(I
don't know that object is appropriate here, something more strongly typed
would be better, most definitely) and the define it like this:
// T here is really your return type. For this, we will assume it is
IP_ADAPTER_INFO
static IEnumerable<IP_ADAPTER_INFOGetAdaptersInfoEnumerab le()
{
// Make the call to get the first item, this is the api call to
GetAdaptersInfo
...
// This is the pointer to the first element in the buffer.
IntPtr buffer = ...;
// Cycle while the buffer is not null.
while (buffer != IntPtr.Zero)
{
// Convert to a structure.
IP_ADAPTER_INFO info = (IP_ADAPTER_INFO)
Marshal.PtrToStructure(buffer);
// Return the structure.
yield return info;
// Move to the next pointer.
buffer = info.Next;
}
}
That's about it really. The support for iterators in C# 2.0 and beyond
really helps you out in this area.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Blip" <bl**@krumpli.comwrote in message
news:2o********************************@4ax.com...
>
public class IP_ADAPTER_INFO //: IEnumerable<object<-maybe
{
public IntPtr Next;
public uint ComboIndex;
public string AdapterName;
...etc...
public IP_ADAPTER_INFO(IntPtr baseAddress)
{
this.Next =
CustomMarshal.GetIntPtr(baseAddress, 0);
this.ComboIndex =
CustomMarshal.GetUInt32(baseAddress, 4);
this.AdapterName =
CustomMarshal.PtrToStringAscii(baseAddress, 8, 256);
...etc...
}
/*
private class IP_ADAPTER_INFO_Enumerator
{
private IP_ADAPTER_INFO IAO;
private int index;
public IP_ADAPTER_INFO_Enumerator(IP_ADAPTER_INFO IAO)
{
this.IAO = IAO;
index = -1;
}
//Increment index
public bool MoveNext()
{
index++;
if (index >= IAO.
}
}
*/
}
I started to try to make it enumerable , but can figure out what to
index on... never done this before. Is this the right path?
Thanks