1

I've recently had to make a forray into decompiling a colleague's code while they're away, and found that most of it looks surprisingly nice (thanks ILSpy), with the notable exception of a couple of places where we needed to use dynamic - these got mangled into several parts:

  1. A call site container - i.e. what resembles a class in definition, but let's say the method in which dynamic was used was DoStuff, would have a declaration along the lines of public /* static? I forget */ class <DoStuff>CallSiteContainer_Plus_Some_Weirdness { /* bunch of CallSite fields */ }
  2. A lot of code that checks whether various CallSites within the container have been assigned and assigns them before usage as required using approaches I really don't get yet.

My question is regarding the syntax of the class declaration in the 1st point. It looks like a generic class, but it clearly isn't. Can anyone explain what's going on there?

Please note, I'm not looking for help in working out the original code - I've already managed to do that by judicious use of find and replace, and breaking out the autogenerated code from everything else. But I'd like to understand how the CallSite container syntax is a valid class name!

tobriand
  • 1,095
  • 15
  • 29
  • Apologies in advance for the lack of a full code sample - the machine I'm asking from doesn't have VS. If I get a chance I'll update the question with a proper example in the week. Suffice to say, you can get the same effect by doing a simple call on a dynamic object, and decompiling the method with ILSpy. – tobriand Aug 23 '15 at 09:56
  • From what I can see (just from the IL code) - there is no class that you're describing. `System.Runtime.CompilerServices.CallSite.Create` is merely a method that allows you to dynamically invoke a method on an object via reflection. Maybe this is `ILSpy` trying to make sense of it? But from what I've tested, there are simply calls to `CallSite`, and none of these generated classes. – Rob Aug 23 '15 at 10:04
  • Fair enough... so really it's probably just a case of pushing the limits of a decompiler. I managed to find a reference to a call site container in the Google Books samples for `C# 4.0 Unleashed`, so figured it was legitimate syntax (but the explanation was just not included in the sample). Anyway, will paste in a sample in the week so others can at least see what I'm talking about. – tobriand Aug 23 '15 at 10:09

1 Answers1

3

Here's an example of such auto-generated class:

private static class <>o__0
{
    public static CallSite<Action<CallSite, Type, object>> <>p__0;
}

If you are worried about the <>o__0 class name and the <>p__0 field name, then you are right, those are not valid C# names but this doesn't mean that they are not valid IL names which is what the compiler generates. The reason why it uses such special symbols is to ensure that they will never conflict with class names that you as a developer might have written.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928