| 1 | namespace CascadeIDE.Services; |
| 2 | |
| 3 | /// <summary>SDK implicit namespace imports (Microsoft.NET.Sdk / Web).</summary> |
| 4 | public static class CSharpSdkImplicitUsingsCatalog |
| 5 | { |
| 6 | private static readonly string[] NetSdk = |
| 7 | [ |
| 8 | "System", |
| 9 | "System.Collections.Generic", |
| 10 | "System.IO", |
| 11 | "System.Linq", |
| 12 | "System.Net.Http", |
| 13 | "System.Threading", |
| 14 | "System.Threading.Tasks", |
| 15 | ]; |
| 16 | |
| 17 | private static readonly string[] WebSdk = |
| 18 | [ |
| 19 | "System.Net.Http.Json", |
| 20 | "Microsoft.AspNetCore.Builder", |
| 21 | "Microsoft.AspNetCore.Hosting", |
| 22 | "Microsoft.AspNetCore.Http", |
| 23 | "Microsoft.AspNetCore.Routing", |
| 24 | "Microsoft.Extensions.Configuration", |
| 25 | "Microsoft.Extensions.DependencyInjection", |
| 26 | "Microsoft.Extensions.Hosting", |
| 27 | "Microsoft.Extensions.Logging", |
| 28 | ]; |
| 29 | |
| 30 | public static IReadOnlyList<string> ForProjectSdk(string? sdkAttribute, bool implicitUsingsEnabled) |
| 31 | { |
| 32 | if (!implicitUsingsEnabled) |
| 33 | return []; |
| 34 | |
| 35 | var list = new List<string>(NetSdk); |
| 36 | if (SdkIncludesWeb(sdkAttribute)) |
| 37 | list.AddRange(WebSdk); |
| 38 | |
| 39 | return list; |
| 40 | } |
| 41 | |
| 42 | private static bool SdkIncludesWeb(string? sdkAttribute) |
| 43 | { |
| 44 | if (string.IsNullOrWhiteSpace(sdkAttribute)) |
| 45 | return false; |
| 46 | |
| 47 | foreach (var part in sdkAttribute.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) |
| 48 | { |
| 49 | if (part.Contains("Microsoft.NET.Sdk.Web", StringComparison.OrdinalIgnoreCase)) |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | return false; |
| 54 | } |
| 55 | } |
| 56 | |