we have a product where we can run VB.NET functions within a C# API. We can pass arguments to these VB.NET functions with an Object[]. Lets say we have the following invocation within the C# API where we pass 3 Parameters to a VBFunction:
var scriptParameters = new object[]
{
new List<Object>()
{
new { FirstName = "Dave", LastName = "King" },
new { FirstName = "Aron", LastName = "Lee" },
new { FirstName = "Gabbi", LastName = "Cole" },
},
"Managers",
"de-DE"
};
var scriptResult = scriptRunner.Invoke("VBFunction", scriptParameters);
Now the first argument -- a List of Objects with Property FirstName, LastName -- is received by the VBFunction as a List of anonymous objects. These anonymous objects should be casted into an Object that is known to the VBFunction in order to be able to work with these objects. For a reason, we cannot set Option Strict off in the code or the compiler in order to use late binding.
Using CType() in order to cast the anonymous object into a similar type in VB.NET didn't worked either and raised an exception.
Do you know an elegant way to transform these anonymous objects into a useful object in the VB.NET script?
Best regards
Aucun commentaire:
Enregistrer un commentaire