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.

95 lines
2.7 KiB

  1. // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Threading.Tasks;
  20. namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
  21. {
  22. public class UsingVariables
  23. {
  24. public IDisposable GetDisposable()
  25. {
  26. return null;
  27. }
  28. public IAsyncDisposable GetAsyncDisposable()
  29. {
  30. return null;
  31. }
  32. private void Use(IDisposable disposable)
  33. {
  34. }
  35. private void Use(IAsyncDisposable asyncDisposable)
  36. {
  37. }
  38. public void SimpleUsingVar()
  39. {
  40. Console.WriteLine("before using");
  41. using IDisposable disposable = GetDisposable();
  42. Console.WriteLine("inside using");
  43. Use(disposable);
  44. }
  45. public void NotAUsingVar()
  46. {
  47. Console.WriteLine("before using");
  48. using (IDisposable disposable = GetDisposable())
  49. {
  50. Console.WriteLine("inside using");
  51. Use(disposable);
  52. }
  53. Console.WriteLine("outside using");
  54. }
  55. public void UsingVarInNestedBlocks(bool condition)
  56. {
  57. if (condition)
  58. {
  59. using IDisposable disposable = GetDisposable();
  60. Console.WriteLine("inside using");
  61. Use(disposable);
  62. }
  63. Console.WriteLine("outside using");
  64. }
  65. public void MultipleUsingVars(IDisposable other)
  66. {
  67. Console.WriteLine("before using");
  68. using IDisposable disposable = GetDisposable();
  69. Console.WriteLine("inside outer using");
  70. using IDisposable disposable2 = other;
  71. Console.WriteLine("inside inner using");
  72. Use(disposable);
  73. Use(disposable2);
  74. }
  75. public async Task SimpleUsingVarAsync()
  76. {
  77. Console.WriteLine("before using");
  78. await using IAsyncDisposable asyncDisposable = GetAsyncDisposable();
  79. Console.WriteLine("inside using");
  80. Use(asyncDisposable);
  81. }
  82. }
  83. }