Reflection does not respect @ symbol with reserved keyword classes
I have a situation where the following class is created by the code generator. I don't have a control of how it generates.
using System;
using System.Reflection;
namespace MyClasses
{
public class @event { };
public class Program
{
public static void Main()
{
@event e = (@event) (Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "MyClasses.@event")).Unwrap();
Console.WriteLine("Created.");
}
}
}
As you can see that it sees the class name with event
reserved word, and it adds @ sign. After that it tries to create an object of the same using reflection by passing @ symbol, which reflection rejects.
If I replace it with
@event e = (@event) (Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "MyClasses.event")).Unwrap();
It works.
What is the possible solution here? I don't have a control on how it adds @ or uses @ ? I understand that reflection does not know about @ symbol being added. Thus, there has to be a way for the reflection to ignore @symbol while creating an object because technically you cannot have @ in your variable or a class name.
Fiddler link: https://dotnetfiddle.net/wBs7GA
do you know?
how many words do you know