elsa-core/src/scripting/Elsa.Scripting.JavaScript/Services/NullResultConverter.cs
Craig Fowler 8e16f5f269 Related to #761 - Refactor complex conversion
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.
2021-04-01 20:25:09 +02:00

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));
}
}
}