This removes all of the (now actually non-trivial) conversion logic from the class which is actually responsible for executing the Jint engine. This moves it all to a new service which uses chain of responsibility to convert the result, using one of a few different mechanisms. Of note is the handling of ExpandoObject when no specific type information has been provided, and also the handling of enumerables, with the exception of strings.
20 lines
626 B
C#
20 lines
626 B
C#
using System;
|
|
|
|
namespace Elsa.Scripting.JavaScript.Services
|
|
{
|
|
public class NullResultConverter : IConvertsJintEvaluationResult
|
|
{
|
|
readonly IConvertsJintEvaluationResult wrapped;
|
|
|
|
public object? ConvertToDesiredType(object? evaluationResult, Type desiredType)
|
|
{
|
|
if(evaluationResult is null) return null;
|
|
return wrapped.ConvertToDesiredType(evaluationResult, desiredType);
|
|
}
|
|
|
|
public NullResultConverter(IConvertsJintEvaluationResult wrapped)
|
|
{
|
|
this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
|
|
}
|
|
}
|
|
} |