TheSwamp
Code Red => .NET => Topic started by: It's Alive! 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
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;
}
Thanks
-
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<>
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
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;
}
Thanks
-
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<>
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
-
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()
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<>
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
-
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
-
IOW, you're writing your own .NET API for IntelliCAD ? :o
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
-
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()
Well it does not increment the selection set like AutoCad does
http://www.theswamp.org/index.php?topic=12218.msg151554#msg151554
-
Sorry, I don't follow.
What doesn't increment the selection set like AutoCAD does?
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()
Well it does not increment the selection set like AutoCad does
http://www.theswamp.org/index.php?topic=12218.msg151554#msg151554
-
Did you click the link?
Edit Sorry,
Intellicad ,when I pass a selection set through the Resultbuffer.
Autocad would not return the same selection set name. It looks like it’s handled differently internally though.
Acad <Selection set: 2> , Icad <Selection set: 115643127>
-
Anyway , here is what I have so far if anyone is interested
-
Hi Dan.
When using a generic list type, rather than having separate
overloaded constructors for arrays and List<T>, you can
write just one:
public class MyList<T> : List<T>
{
// accept any object that can enumerate T, such as
// T[]; List<T>; ICollection<T>; IEnumerable<T>, etc.
public MyList(IEnumerable<T> items)
{
AddRange(items);
}
//.......
}
Anyway , here is what I have so far if anyone is interested
-
Way cool. Thanks Tony!
I sure am glad you hang out here at TheSwamp.
It’s so great to be able to learn from someone with your talents.
Thanks