Parsing.cs 962 B

12345678910111213141516171819202122232425262728293031323334
  1. using Avalonia.Controls;
  2. using Avalonia.Markup.Parsers;
  3. using BenchmarkDotNet.Attributes;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace Avalonia.Benchmarks.Markup
  8. {
  9. [MemoryDiagnoser]
  10. public class Parsing
  11. {
  12. [Benchmark]
  13. public void ParseComplexSelector()
  14. {
  15. var selectorString = "ListBox > TextBox /template/ TextBlock[IsFocused=True]";
  16. var parser = new SelectorParser((ns, s) =>
  17. {
  18. switch (s)
  19. {
  20. case "ListBox":
  21. return typeof(ListBox);
  22. case "TextBox":
  23. return typeof(TextBox);
  24. case "TextBlock":
  25. return typeof(TextBlock);
  26. default:
  27. return null;
  28. }
  29. });
  30. var selector = parser.Parse(selectorString);
  31. }
  32. }
  33. }