之前看过一个自定义函数。代码是这样的,就不必考虑后面参数的数量。但是不懂原理是否一下。
try
If dr("参数") IsNot Nothing Then
Dim cs() As String
cs =dr("参数").Split(",")'分离参数
If cs.Length - 1=0 Then '如果没参数,则执行functions.execute(函数名)
Functions.execute(cs(0))'执行指定函数
ElseIf cs.Length - 1>0 Then '如果有参数,则将dr("参数")分解为函数名和参数执行functions.execute(函数名,参数1,参数2,……)
Dim objs As New List(Of object)
Dim Names() As object
For i As Integer =1 To cs.Length -1
If cs(i) = "e" Then
objs.Add(e)
Else
Functions.remove("函数")
Dim Code As String
Code = "return " & cs(i)
Functions.Add("函数",Code)
Functions.Complie()
Dim obj = Functions.Execute("函数")
objs.Add(obj)
End If
Next
Names=objs.ToArray() '将集合转换为数组
Functions.execute(cs(0),Names)'执行指定函数
End If
End If
catch ex As exception
End try