elsa-core/src/scripting/Elsa.Scripting.JavaScript/Services/PlainObjectResultConverter.cs

28 lines
920 B
C#
Raw Normal View History

using System;
namespace Elsa.Scripting.JavaScript.Services
{
public class PlainObjectResultConverter : IConvertsJintEvaluationResult
{
2021-06-19 09:51:06 +00:00
private readonly IConvertsJintEvaluationResult _wrapped;
public object? ConvertToDesiredType(object? evaluationResult, Type desiredType)
{
2021-06-19 09:51:06 +00:00
if (evaluationResult == null)
return null;
if(desiredType == typeof(object))
return evaluationResult;
2021-06-19 09:51:06 +00:00
if (evaluationResult.GetType() == desiredType || desiredType.IsInstanceOfType(evaluationResult))
return evaluationResult;
2021-06-19 09:51:06 +00:00
return _wrapped.ConvertToDesiredType(evaluationResult, desiredType);
}
public PlainObjectResultConverter(IConvertsJintEvaluationResult wrapped)
{
2021-06-19 09:51:06 +00:00
this._wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
}
}
}