Generate Method adds "using System;" to target file
Environment data
dotnet --info output:
.NET Command Line Tools (1.0.1)
Product Information: Version: 1.0.1 Commit SHA-1 hash: 005db40cd1
Runtime Environment: OS Name: Windows OS Version: 10.0.15063 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.1
VS Code version: 1.12.2
C# Extension version: 1.10.0
Steps to reproduce
- Write a call site of an undeclared method (eg.
Bar();) - Press CTRL+. and select "Generate Method"
Expected behavior
A configurable option to generate the method without the "using System;" statement, for example:
void Bar()
{
throw new System.NotImplementedException();
}
This would be useful in Unity solutions, since there are class name conflicts between the namespaces System and UnityEngine.
Actual behavior
The following is added to the top of the .cs file:
using System;
This often will cause naming conflicts between classes, for example between System.Random and UnityEngine.Random.
There is no configurable option for this, but it's a known issue that has just been addressed in Visual Studio. In VS, we've recently special-cased the generated throw new System.NotImplementationException(); to not introduce a new using for System. I filed this issue awhile back in https://github.com/dotnet/roslyn/issues/8257 and it was fixed with https://github.com/dotnet/roslyn/pull/10512.
When we take a newer version of Roslyn into OmniSharp, we'll pick up this new behavior for free. So, there won't be an option to configure this behavior, but it will no longer introduce "using System" for "throw new System.NotImplementedException". In my experience, that's 95% of the problem. :smile:
Does that solution work for you?
cc @Pilchie and @cyrusnajmabadi as FYI
@DustinCampbell Yes, that solution sounds great! Thanks for the quick response.
Hi,
Sorry to revive an old issue but I've never seen the solution implemented. I still have the using statement added whenever I ask to "Generate Method".
VSCode version : 1.74.3 C# exstension version : v1.52.2
dotnet --info output:
SDK .NET (reflétant tous les fichiers global.json) :
Version: 6.0.202
Commit: f8a55617d2
Environnement d'exécution :
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: c:\program files\dotnet\sdk\6.0.202\
Host (useful for support): Version: 6.0.4 Commit: be98e88c76
.NET SDKs installed: 2.1.509 [c:\program files\dotnet\sdk] 3.0.101 [c:\program files\dotnet\sdk] 6.0.202 [c:\program files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.13 [c:\program files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.13 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.1 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.4 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.13 [c:\program files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.1 [c:\program files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [c:\program files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [c:\program files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.1 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.2 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.4 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]