Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous class members in vb.net

I am trying to use a class from a C# assembly in vb.net. The class has ambiguous members because vb.net is case insensitive. The class is something like this:

public class Foo {

  public enum FORMAT {ONE, TWO, THREE};

  public FORMAT Format {
    get {...}
    set {...}
   }
}

I try to access the enum: Foo.FORMAT.ONE

This is not possible because there is also a property named 'format'.

I can not change the C# assembly. How can I get around this and reference the enum from vb.net?

like image 250
tvaananen Avatar asked Oct 15 '08 20:10

tvaananen


2 Answers

I don't think you can get around this. Get in touch with the author of the C# component you are trying to use and convince them to fix their code.

Incidentally, this is the primary reason behind the CLSCompliant(true) attribute, which if you are writing APIs or other code that has a high probability of being used by other languages you should always set. It would have flagged this issue for the original author to be aware of and fix correctly.

like image 68
Scott Dorman Avatar answered Nov 14 '22 05:11

Scott Dorman


There are a couple of ways you can work around it, but neither one is really a good option.

One is to create a C# project and completely wrap the class, changing the ambiguous members into unambiguous ones. Depending on how big the class is, it could be a lot of work, though you only have to wrap the members you need, obviously.

The other is to use reflection, which isn't as much work as wrapping, but is still pointless work compared to the author just writing the code correctly in the first place.

like image 4
Ryan Lundy Avatar answered Nov 14 '22 05:11

Ryan Lundy