简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM