Nullable: System.Runtime.InteropServices.CustomMarshalers/WindowsRuntime (#23930)
[platform/upstream/coreclr.git] / src / System.Private.CoreLib / src / System / Runtime / InteropServices / WindowsRuntime / IClosable.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 #nullable enable
6 using System.Diagnostics;
7 using Internal.Runtime.CompilerServices;
8
9 namespace System.Runtime.InteropServices.WindowsRuntime
10 {
11     // Local definition of Windows.Foundation.IClosable
12     [ComImport]
13     [Guid("30d5a829-7fa4-4026-83bb-d75bae4ea99e")]
14     [WindowsRuntimeImport]
15     internal interface IClosable
16     {
17         void Close();
18     }
19
20     // Adapter class - converts IClosable.Close calls to Disposable.Dispose
21     internal sealed class IDisposableToIClosableAdapter
22     {
23         private IDisposableToIClosableAdapter()
24         {
25             Debug.Fail("This class is never instantiated");
26         }
27
28         public void Close()
29         {
30             IDisposable _this = Unsafe.As<IDisposable>(this);
31             _this.Dispose();
32         }
33     }
34
35     // Adapter class which converts IDisposable.Dispose calls into IClosable.Close
36     internal sealed class IClosableToIDisposableAdapter
37     {
38         private IClosableToIDisposableAdapter()
39         {
40             Debug.Fail("This class is never instantiated");
41         }
42
43         private void Dispose()
44         {
45             IClosable _this = Unsafe.As<IClosable>(this);
46             _this.Close();
47         }
48     }
49 }