473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Can a class be enumerated or can it be made enumerable?


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
Dec 9 '07 #1
1 1402
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
Dec 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Riis | last post by:
This all pertains to the above mentioned article. Anyone want to read it (it's rather neat, actually), here's the address: http://www.cuj.com/documents/s=8205/cujweb0305meynard/ Anyway, I was...
0
by: Brandon | last post by:
Hello all, and thanks for taking a look at this. First off, the project I am working on is a server/client application that contains a shared assembly of common classes between the two...
8
by: ypjofficial | last post by:
Hi all, In what way does the enumerated data type contibute to the size of a class if its part of that class? eg. #include <iostream.h> class one { public:
1
by: dhtmlkitchen | last post by:
I think this is not possible... var fnProto = Function().prototype; var badAss = { constructor : "Chuck Norris" }; result = ; function isConstructorEnumerable( ocean, pacific ) {
9
by: tadmill | last post by:
Is it possible to pass a generic parameter of the same class to to its constructor, where the "T" type passed in the constructor is different than the "T" type of the instanced class? ie, ...
4
by: Kenneth Porter | last post by:
Can someone point me to documentation or examples on how to implement an Enumerable interface in C++/CLI? I've found examples for C# but nothing for C++. I'm wrapping a native library that...
1
by: jc | last post by:
RE: Why use a CollectionBase class here vs dataset or dataview? I'm looking at some vb.net 2005 code that was generated from a homegrown Codesmith Template that generate all of the retreival and...
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.