This topic is quite old, but here's my new attempt for a Trans method working as the LISP one (it accepts either integer, ObjectId or Vector3d as argument).
The extension method uses some C# 7 functional programming features (local function and pattern matching).
static class Extension
{
[DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedTrans")]
static extern int acedTrans(double[] point, IntPtr fromRb, IntPtr toRb, int disp, double[] result);
public static Point3d Trans(this Point3d source, object from, object to, bool disp = false)
{
ResultBuffer toResBuf(object obj)
{
switch (obj)
{
case int i:
return new ResultBuffer
(new TypedValue
(5003, i
)); case ObjectId id:
return new ResultBuffer
(new TypedValue
(5006, id
)); case Vector3d v:
return new ResultBuffer
(new TypedValue
(5009,
new Point3d
(v
.X, v
.Y, v
.Z))); default:
throw new Autodesk
.AutoCAD.Runtime.Exception(ErrorStatus
.InvalidInput); }
}
double[] result
= new double[3]; int status = acedTrans(source.ToArray(), toResBuf(from).UnmanagedObject, toResBuf(to).UnmanagedObject, disp ? 1 : 0, result);
if (status == 5100)
return new Point3d
(result
); else
throw new Autodesk
.AutoCAD.Runtime.Exception(ErrorStatus
.InvalidInput); }
}