Thanks.
And, how about this one?
namespace Namespace1
{
public static class Class1
{
[LispFunction( "kaboom" )]
public static bool Kaboom( ResultBuffer args )
{
if( args == null )
return false;
TypedValue[] array = args.AsArray();
if( array.Length != 2 )
return false;
TypedValue a = array[0];
TypedValue b = array[1];
return a == b;
}
}
}
Command: (kaboom nil nil)
[edit]
For anyone interested, the bug is triggered by the incorrect use of object.Equals( object ) within the TypedValue's overload of the == operator. It should be using object.Equals( object, object ), rather than the instance Equals( object) method, which of course, requires a non-null instance. You might note that while the managed runtime catches most exceptions thrown by calls to a LispFunction, NullReferenceException is not one of them.
You can avoid this problem by pre-processing TypedValues that come from LISP like so:
namespace Namespace1
{
public static class MyExtensions
{
// call this in lieu of ResultBuffer.AsArray()
public static TypedValue[] ToArray( this ResultBuffer args )
{
if( args == null )
return new TypedValue
[0]; return args.Cast<TypedValue>()
.Select( tv
=> object.Equals( tv
.Value,
null ) ? new TypedValue
( tv
.Value, Type
.Missing ) : tv
) .ToArray();
}
}
}