I need to support a method named ‘send-request’ as an extension function to be used in an XSLT transformation. This is provided by an extension object on XslCompiledTransform. The cool thing about extension objects vs. <msxsl:script> is, well, that I don’t have to use <msxsl:script>, you just declare the namespace and call the function. The bad thing is that the function name must match exactly the CIL method name.
So, I’m wondering, is there a .NET language that supports hyphens in method names ? CLS compliance is not required, the method is invoked using reflection.
Or, can I use some technique that modifies the IL of an assembly to change the method name ?
Or, is there a way to intercept the reflection GetMethod call and trick the caller that a method ‘send-request’ exists, but return a ‘SendRequest’ method instead ?
You can do this using reflection.
I compiled the following into an assembly using ILAsm (I cut out all the fluff necessary to make this actually compile; these are just the salient bits (pun intended)):
I defined this method in a class named
Programin a namespace namedTest. Note that the method name is surrounded by single quotes. This is per the spec (ECMA #335):Then:
This produced output:
I doubt that is the possible in the usual .NET languages. I don’t know of any languages that allow/require you to “escape” identifiers. Without that, could you imagine trying to disambiguate the following:
Maybe there’s a COBOL.NET where you could do this, I don’t know.