I have a method which takes a stored procedure name and a Microsoft.VisualBasic.Collection? I am referencing a vb project in which I have to pass in a collection to this method, but the current project I am in is in c#, so I am unclear what I can pass into the method?
Here is the vb call:
public void CallStoredProc(string spName, Microsoft.VisualBasic.Collection params);
In my c# app, I need to call this an pass in the appropriate c# object to params.
One option is to simply use the Collection type directly from C#. This is a standard type in the Microsoft.VisualBasic.dll assembly and can be used from any .Net language.
The closest collection in the standard BCL though is Hashtable. Converting between Hashtable and Collection should be fairly straight forward
For example
using VBCollection = Microsoft.VisualBasic.Collection;
...
public static VBCollection ToVBCollection(this Hashtable table) {
var collection = new VBCollection();
foreach (var pair in table) {
// Note: The Add method in collection takes value then key.
collection.Add(pair.Value, pair.Key);
}
return collection;
}
Note: This is not a direct mapping though. The Collection type supports a number of operations which Hashtable does not like: before and after values, index by number or key, etc ... My approach would be to use one type consistently throughout the application and change either the C# or VB project appropriately
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With