Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is equivalent to Microsoft.VisualBasic.Collection in c#?

Tags:

c#

vb.net

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.

like image 332
Xaisoft Avatar asked May 24 '11 18:05

Xaisoft


1 Answers

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

like image 81
JaredPar Avatar answered Oct 21 '22 12:10

JaredPar