Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference identifiers with dollar signs from C#?

Tags:

c#

scala

ikvm

I'm trying to use a DLL generated by ikvmc from a jar file compiled from Scala code (yeah my day is THAT great). The Scala compiler seems to generate identifiers containing dollar signs for operator overloads, and IKVM uses those in the generated DLL (I can see it in Reflector). The problem is, dollar signs are illegal in C# code, and so I can't reference those methods.

Any way to work around this problem?

like image 478
Martin Avatar asked Oct 09 '12 22:10

Martin


People also ask

Is dollar valid identifier in C?

The dollar sign $ is a valid identifier character in the Microsoft C++ compiler (MSVC).

Can an identifier have a dollar sign?

Dollar signs in identifiersDollar ( $ ) signs are permitted in identifiers.

What does dollar in C mean?

The Canadian dollar (symbol: $; code: CAD; French: dollar canadien) is the currency of Canada. It is abbreviated with the dollar sign $, there is no standard disambiguating form, but the abbreviation Can$ is often suggested by notable style guides for distinction from other dollar-denominated currencies.

Is dollar sign valid variable name?

Rules for naming variables: The convention is to always use a letter of the alphabet. The dollar sign and the underscore are discouraged. After the first initial letter, variable names may also contain letters and the digits 0 to 9. No spaces or special characters are allowed.


1 Answers

You should be able to access the funky methods using reflection. Not a nice solution, but at least it should work. Depending on the structure of the API in the DLL it may be feasible to create a wrapper around the methods to localise the reflection code. Then from the rest of your code just call the nice wrapper.

The alternative would be to hack on the IL in the target DLL and change the identifiers. Or do some post-build IL-hacking on your own code.

like image 142
Andrew Cooper Avatar answered Oct 22 '22 18:10

Andrew Cooper