Thanks Dan. I posted a stripped down version of that class
because the remainder was dependent on other things that
would needed to have come along for the ride.
One thing you might note is that the class has implicit
conversions to/from ResultBuffer, TypedValue[], and
SelectionFilter.
That means that instead of:
TypedValueList arInputArgs = new TypedValueList(rbfArgs.AsArray());
You can just do:
TypedValueList arInputArgs = new TypedValueList(rbfArgs);
// Or for that matter, you can just do this:
TypedValueList arInputArgs = rbfArgs;
// Just to make that clearer:
DBObject myObj = myTrans.GetObject(...);
TypedValueList list = myObj.XData; // assign directly to TypedValueList
// modify list here
myObj.XData = list; // implicitly convert to a ResultBuffer
Also, on the typecasting from DxfCode and LispDataType,
business, you can also clean up code that uses that class,
by adding a few overloaded Add methods, like so:
public void Add(LispDataType type, object value)
{
Add( new TypedValue((int) type, value));
}
public void Add(DxfCode code, object value)
{
Add( new TypedValue((int) code, value));
}
That means, you can add items to the list, more easily
and cleanly, at a slight cost:
TypedValueList list = new TypedValueList();
list.Add( LispDataType.ListBegin, 0 );
list.Add( LispDataType.Double, 99.000 );
list.Add( LispDataType.String, "hello world" );
list.Add( LispDataType.ListEnd, 0 );
With those two overloads, there's no need to create
TypedValues to add items to the list, or typecast from
either DxfCode or LispDataType.
Lastly, another improvement is to overload the constructor
to take IEnumerable arguments, which allows you to create
a new instance that's populated from any type that can
enumerate TypedValues (e.g. ResultBuffer, TypedValue[],
ArrayList, List<TypedValue>, or another TypedValueList):
public TypedValueList( IEnumerable<TypedValue> source )
{
AddRange( source );
}
public TypedValueList( IEnumerable source )
{
foreach( TypedValue v in source )
Add( v );
}
How about using TonyT’s awesome TypedValueList class ?
http://www.theswamp.org/index.php?topic=14495.msg186823#msg186823
[LispFunction("PolarPoint")]
public ResultBuffer DotNetPolarPoint(ResultBuffer rbfArgs)
{
//TonyT's cool TypedValueList
TypedValueList arInputArgs = new TypedValueList(rbfArgs.AsArray());
TypedValueList arOutputArgs = new TypedValueList();
//
Point3d co = (Point3d)arInputArgs[0].Value;
double ang = (double)arInputArgs[1].Value;
double dst = (double)arInputArgs[2].Value;
//
arOutputArgs.Add((int)LispDataType.Point3d,
new Point3d(co.X +
(dst * Math.Cos(ang)),
co.Y + (dst * Math.Sin(ang)),
co.Z));
return arOutputArgs; //edit
}
This seems to be the way to go, thanks Tony