obfuz/Editor/Virtualization/Functions/FunctionBase.cs

31 lines
1.1 KiB
C#

using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
namespace Obfuz.Virtualization
{
public abstract class FunctionBase : IFunction
{
public abstract DataNodeType ReturnType { get; }
public abstract void CreateArguments(DataNodeType type, object value, CreateExpressionOptions options, List<ConstValue> args);
public ConstExpression CreateCallable(DataNodeType type, object value, CreateExpressionOptions options)
{
var args = new List<ConstValue>();
CreateArguments(type, value, options, args);
options.depth += 1;
var argNodes = new List<IDataNode>();
foreach (ConstValue cv in args)
{
var argNode = options.expressionCreator.CreateRandom(cv.type, cv.value, options);
argNodes.Add(argNode);
}
return new ConstExpression(this, args.Select(a => options.expressionCreator.CreateRandom(a.type, a.value, options)).ToList(), new ConstValue(type, value));
}
}
}