Code Red > .NET

A New ResultBuffer Class

(1/3) > >>

It's Alive!:
Opinion needed
I want to write a resbuf wrapper class for my little Intellicad project.
If you were writing one using  .Net 2.0 generics would you use a similar TypedValue structure
or use one of the built-in generic dictionaries I.e


--- Code: ---static Dictionary<int, Object^> ^ToDictionary(resbuf * inl_List)
{
    Dictionary<int, Object^> ^mDict = gcnew Dictionary<int, Object^>();
    //
    for (resbuf * lList=inl_List; lList; lList=lList->rbnext)
    {
        switch ( lList->restype )
        {
        case RTSTR:
            mDict->Add(lList->restype , safe_cast<Object^>(gcnew String(lList->resval.rstring)));
            break;

        case RTSHORT :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rint));
            break;

        case RTLONG :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rlong));
            break;

        case RTREAL :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rreal));
            break;
            //todo add the rest of the types
        }
    }
    return mDict;
}
//
static List<KeyValuePair<int, Object^>> ^ToList(resbuf * inl_List)
{
    List<KeyValuePair<int, Object^>> ^mList = //
        gcnew List<KeyValuePair<int, Object^>>(ToDictionary(inl_List));
    return mList;
}

--- End code ---

Thanks

TonyT:
A dictionary stores a list of key/value pairs with the
constraint that there can be no duplicate keys, which
I think rules it out for the intended purpose.

I would just yank the source for TypedValue from the
Autodesk libraries with reflector and use it with a List<>


     

--- Quote from: Danielm103 on April 19, 2007, 07:33:53 AM ---Opinion needed
I want to write a resbuf wrapper class for my little Intellicad project.
If you were writing one using  .Net 2.0 generics would you use a similar TypedValue structure
or use one of the built-in generic dictionaries I.e


--- Code: ---static Dictionary<int, Object^> ^ToDictionary(resbuf * inl_List)
{
    Dictionary<int, Object^> ^mDict = gcnew Dictionary<int, Object^>();
    //
    for (resbuf * lList=inl_List; lList; lList=lList->rbnext)
    {
        switch ( lList->restype )
        {
        case RTSTR:
            mDict->Add(lList->restype , safe_cast<Object^>(gcnew String(lList->resval.rstring)));
            break;

        case RTSHORT :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rint));
            break;

        case RTLONG :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rlong));
            break;

        case RTREAL :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rreal));
            break;
            //todo add the rest of the types
        }
    }
    return mDict;
}
//
static List<KeyValuePair<int, Object^>> ^ToList(resbuf * inl_List)
{
    List<KeyValuePair<int, Object^>> ^mList = //
        gcnew List<KeyValuePair<int, Object^>>(ToDictionary(inl_List));
    return mList;
}

--- End code ---

Thanks


--- End quote ---

It's Alive!:

--- Quote from: TonyT on April 19, 2007, 08:37:45 AM ---A dictionary stores a list of key/value pairs with the
constraint that there can be no duplicate keys, which
I think rules it out for the intended purpose.

I would just yank the source for TypedValue from the
Autodesk libraries with reflector and use it with a List<>

--- End quote ---

Thanks Tony,
I was headed down the wrong path using the Dictionary<>.  :oops:
I was considering using the built-n KeyValuePair<> but opted to make a TypedValue class as you suggested.
Well now the easy part works getting an unmanaged resbuf in a list now I just have to figure out how to do the reverse. 8-)
Dan

TonyT:
Marshalling beween resbuf and TypedValue is not exactly
trivial, because some unmanged types have very different
managed representations (namely, unmanaged selection sets
and the managed counterpart are vastly different).

To see how involved it is, have a look at these
methods of the ResultBuffer in reflector:

TypedValueToResbuf()
ResbufToTypedValue()



--- Quote from: Danielm103 on April 19, 2007, 02:59:43 PM ---
--- Quote from: TonyT on April 19, 2007, 08:37:45 AM ---A dictionary stores a list of key/value pairs with the
constraint that there can be no duplicate keys, which
I think rules it out for the intended purpose.

I would just yank the source for TypedValue from the
Autodesk libraries with reflector and use it with a List<>

--- End quote ---

Thanks Tony,
I was headed down the wrong path using the Dictionary<>.  :oops:
I was considering using the built-n KeyValuePair<> but opted to make a TypedValue class as you suggested.
Well now the easy part works getting an unmanaged resbuf in a list now I just have to figure out how to do the reverse. 8-)
Dan


--- End quote ---

It's Alive!:
Not only that, but I will also have to build each of the Types as well, Point2d, Point3d …
Might be biting off more than I can chew. But I am learning tons

Navigation

[0] Message Index

[#] Next page

Go to full version