Reputation: 21
So I ran a C# university program through de4dot and then reflector to decompile it and the following error appeared when I ran it in VS.
[assembly: System.Runtime.CompilerServices.Extension]
Error CS1112 Do not use 'System.Runtime.CompilerServices.ExtensionAttribute'. Use the 'this' keyword instead. Client C:\Users\user\Desktop\333\as2\decom\AssemblyInfo.cs 15 Active
I tried replacing the code with this and this() among other things but that just causes other problems. Can someone explain what I am to replace with 'this'? I feel like I am missing something obvious here.
Upvotes: 2
Views: 7176
Reputation: 25623
The [assembly: Extension]
attribute is added to an assembly by the compiler when the assembly contains extension methods. This happens automatically, and based on the error you're seeing, the compiler doesn't want you doing it explicitly. Assuming the rest of the decompiler output is correct, comment out the assembly-level attribute, and you should be fine.
That said, you should never assume that a decompiler's output is correct.
Upvotes: 9
Reputation: 1503899
You're meant to add the this
modifier to the method:
public static class FooExtensions
{
public static void DoSomething(this Foo foo)
{
...
}
}
That makes it an extension method.
In general thought, I wouldn't try to use a decompiler to "round trip" code - decompilers can be useful to see what the compiler has actually done, but there are various situations where the result won't be compilable.
Upvotes: 3