NCalc在vb.net中创建自定义函数

时间:2014-04-21 18:00:38

标签: c# vb.net anonymous-delegates ncalc

在vb2010而不是c#中创建自定义函数的等效代码是什么?

  Expression e = new Expression("SecretOperation(3, 6)");
  e.EvaluateFunction += delegate(string name, FunctionArgs args)
      {
          if (name == "SecretOperation")
              args.Result = (int)args.Parameters[0].Evaluate() + (int)args.Parameters[1].Evaluate();
      };

1 个答案:

答案 0 :(得分:4)

这是怎么做的!

Imports NCalc

Public Class Form1
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim exp As New Expression("SecretOperation(3, 6)")
      AddHandler exp.EvaluateFunction, Sub(str, args)
      If str = "SecretOperation" Then
        args.Result = CInt(args.Parameters(0).Evaluate() + args.Parameters(1).Evaluate())
      End If
    End Sub
  End Sub
End Class

来自文档:http://msdn.microsoft.com/en-us/library/ms172879.aspx