From 1933df00138618c9004b6a6343e2f983df58bd3c Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sun, 25 Jul 2021 00:16:59 -0400 Subject: Some more C# formatting --- .../GodotTools.ProjectEditor/DotNetSolution.cs | 80 +++++++++++----------- .../GodotTools.ProjectEditor/IdentifierUtils.cs | 10 +-- 2 files changed, 45 insertions(+), 45 deletions(-) (limited to 'modules/mono/editor/GodotTools/GodotTools.ProjectEditor') diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs index 284e94810a..355b21d63a 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs @@ -9,15 +9,40 @@ namespace GodotTools.ProjectEditor { public class DotNetSolution { - private string directoryPath; - private readonly Dictionary projects = new Dictionary(); + private const string _solutionTemplate = +@"Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +{0} +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution +{1} + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution +{2} + EndGlobalSection +EndGlobal +"; + + private const string _projectDeclaration = +@"Project(""{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}"") = ""{0}"", ""{1}"", ""{{{2}}}"" +EndProject"; + + private const string _solutionPlatformsConfig = +@" {0}|Any CPU = {0}|Any CPU"; + + private const string _projectPlatformsConfig = +@" {{{0}}}.{1}|Any CPU.ActiveCfg = {1}|Any CPU + {{{0}}}.{1}|Any CPU.Build.0 = {1}|Any CPU"; + + private string _directoryPath; + private readonly Dictionary _projects = new Dictionary(); public string Name { get; } public string DirectoryPath { - get => directoryPath; - set => directoryPath = value.IsAbsolutePath() ? value : Path.GetFullPath(value); + get => _directoryPath; + set => _directoryPath = value.IsAbsolutePath() ? value : Path.GetFullPath(value); } public class ProjectInfo @@ -29,22 +54,22 @@ namespace GodotTools.ProjectEditor public void AddNewProject(string name, ProjectInfo projectInfo) { - projects[name] = projectInfo; + _projects[name] = projectInfo; } public bool HasProject(string name) { - return projects.ContainsKey(name); + return _projects.ContainsKey(name); } public ProjectInfo GetProjectInfo(string name) { - return projects[name]; + return _projects[name]; } public bool RemoveProject(string name) { - return projects.Remove(name); + return _projects.Remove(name); } public void Save() @@ -58,7 +83,7 @@ namespace GodotTools.ProjectEditor bool isFirstProject = true; - foreach (var pair in projects) + foreach (var pair in _projects) { string name = pair.Key; ProjectInfo projectInfo = pair.Value; @@ -66,7 +91,7 @@ namespace GodotTools.ProjectEditor if (!isFirstProject) projectsDecl += "\n"; - projectsDecl += string.Format(ProjectDeclaration, + projectsDecl += string.Format(_projectDeclaration, name, projectInfo.PathRelativeToSolution.Replace("/", "\\"), projectInfo.Guid); for (int i = 0; i < projectInfo.Configs.Count; i++) @@ -79,15 +104,15 @@ namespace GodotTools.ProjectEditor projPlatformsCfg += "\n"; } - slnPlatformsCfg += string.Format(SolutionPlatformsConfig, config); - projPlatformsCfg += string.Format(ProjectPlatformsConfig, projectInfo.Guid, config); + slnPlatformsCfg += string.Format(_solutionPlatformsConfig, config); + projPlatformsCfg += string.Format(_projectPlatformsConfig, projectInfo.Guid, config); } isFirstProject = false; } string solutionPath = Path.Combine(DirectoryPath, Name + ".sln"); - string content = string.Format(SolutionTemplate, projectsDecl, slnPlatformsCfg, projPlatformsCfg); + string content = string.Format(_solutionTemplate, projectsDecl, slnPlatformsCfg, projPlatformsCfg); File.WriteAllText(solutionPath, content, Encoding.UTF8); // UTF-8 with BOM } @@ -97,37 +122,12 @@ namespace GodotTools.ProjectEditor Name = name; } - const string SolutionTemplate = -@"Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -{0} -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -{1} - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -{2} - EndGlobalSection -EndGlobal -"; - - const string ProjectDeclaration = -@"Project(""{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}"") = ""{0}"", ""{1}"", ""{{{2}}}"" -EndProject"; - - const string SolutionPlatformsConfig = -@" {0}|Any CPU = {0}|Any CPU"; - - const string ProjectPlatformsConfig = -@" {{{0}}}.{1}|Any CPU.ActiveCfg = {1}|Any CPU - {{{0}}}.{1}|Any CPU.Build.0 = {1}|Any CPU"; - public static void MigrateFromOldConfigNames(string slnPath) { if (!File.Exists(slnPath)) return; - var input = File.ReadAllText(slnPath); + string input = File.ReadAllText(slnPath); if (!Regex.IsMatch(input, Regex.Escape("Tools|Any CPU"))) return; @@ -151,7 +151,7 @@ EndProject"; }; var regex = new Regex(string.Join("|", dict.Keys.Select(Regex.Escape))); - var result = regex.Replace(input, m => dict[m.Value]); + string result = regex.Replace(input, m => dict[m.Value]); if (result != input) { diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/IdentifierUtils.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/IdentifierUtils.cs index ed77076df3..31363df9ef 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/IdentifierUtils.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/IdentifierUtils.cs @@ -91,7 +91,7 @@ namespace GodotTools.ProjectEditor return identifier; } - static bool IsKeyword(string value, bool anyDoubleUnderscore) + private static bool IsKeyword(string value, bool anyDoubleUnderscore) { // Identifiers that start with double underscore are meant to be used for reserved keywords. // Only existing keywords are enforced, but it may be useful to forbid any identifier @@ -103,14 +103,14 @@ namespace GodotTools.ProjectEditor } else { - if (DoubleUnderscoreKeywords.Contains(value)) + if (_doubleUnderscoreKeywords.Contains(value)) return true; } - return Keywords.Contains(value); + return _keywords.Contains(value); } - private static readonly HashSet DoubleUnderscoreKeywords = new HashSet + private static readonly HashSet _doubleUnderscoreKeywords = new HashSet { "__arglist", "__makeref", @@ -118,7 +118,7 @@ namespace GodotTools.ProjectEditor "__refvalue", }; - private static readonly HashSet Keywords = new HashSet + private static readonly HashSet _keywords = new HashSet { "as", "do", -- cgit v1.2.3