Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. using System.Collections.Generic;
  6. using System.Text.RegularExpressions;
  7. namespace Microsoft.Unity.VisualStudio.Editor
  8. {
  9. internal static class SolutionParser
  10. {
  11. // Compared to the bridge implementation, we are not returning "{" "}" from Guids
  12. private static readonly Regex ProjectDeclaration = new Regex(@"Project\(\""{(?<projectFactoryGuid>.*?)}\""\)\s+=\s+\""(?<name>.*?)\"",\s+\""(?<fileName>.*?)\"",\s+\""{(?<projectGuid>.*?)}\""(?<metadata>.*?)\bEndProject\b", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
  13. private static readonly Regex PropertiesDeclaration = new Regex(@"GlobalSection\((?<name>([\w]+Properties|NestedProjects))\)\s+=\s+(?<type>(?:post|pre)Solution)(?<entries>.*?)EndGlobalSection", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
  14. private static readonly Regex PropertiesEntryDeclaration = new Regex(@"^\s*(?<key>.*?)=(?<value>.*?)$", RegexOptions.Multiline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
  15. public static Solution ParseSolutionFile(string filename, IFileIO fileIO)
  16. {
  17. return ParseSolutionContent(fileIO.ReadAllText(filename));
  18. }
  19. public static Solution ParseSolutionContent(string content)
  20. {
  21. return new Solution
  22. {
  23. Projects = ParseSolutionProjects(content),
  24. Properties = ParseSolutionProperties(content)
  25. };
  26. }
  27. private static SolutionProjectEntry[] ParseSolutionProjects(string content)
  28. {
  29. var projects = new List<SolutionProjectEntry>();
  30. var mc = ProjectDeclaration.Matches(content);
  31. foreach (Match match in mc)
  32. {
  33. projects.Add(new SolutionProjectEntry
  34. {
  35. ProjectFactoryGuid = match.Groups["projectFactoryGuid"].Value,
  36. Name = match.Groups["name"].Value,
  37. FileName = match.Groups["fileName"].Value,
  38. ProjectGuid = match.Groups["projectGuid"].Value,
  39. Metadata = match.Groups["metadata"].Value
  40. });
  41. }
  42. return projects.ToArray();
  43. }
  44. private static SolutionProperties[] ParseSolutionProperties(string content)
  45. {
  46. var properties = new List<SolutionProperties>();
  47. var mc = PropertiesDeclaration.Matches(content);
  48. foreach (Match match in mc)
  49. {
  50. var sp = new SolutionProperties
  51. {
  52. Entries = new List<KeyValuePair<string, string>>(),
  53. Name = match.Groups["name"].Value,
  54. Type = match.Groups["type"].Value
  55. };
  56. var entries = match.Groups["entries"].Value;
  57. var mec = PropertiesEntryDeclaration.Matches(entries);
  58. foreach (Match entry in mec)
  59. {
  60. var key = entry.Groups["key"].Value.Trim();
  61. var value = entry.Groups["value"].Value.Trim();
  62. sp.Entries.Add(new KeyValuePair<string, string>(key, value));
  63. }
  64. properties.Add(sp);
  65. }
  66. return properties.ToArray();
  67. }
  68. }
  69. }