summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs
blob: 847147ade8fdd568dc5b1aa43037a36a34707828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

//

using System;
using System.Security;
using System.Collections;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;

namespace System.Runtime.InteropServices.WindowsRuntime
{

    // Local definition of Windows.Foundation.IClosable
    [ComImport]
    [Guid("30d5a829-7fa4-4026-83bb-d75bae4ea99e")]
    [WindowsRuntimeImport]
    internal interface IClosable
    {
        void Close();
    }

    // Adapter class - converts IClosable.Close calls to Disposable.Dispose
    internal sealed class IDisposableToIClosableAdapter
    {
        private IDisposableToIClosableAdapter()
        {
            Contract.Assert(false, "This class is never instantiated");
        }

        [SecurityCritical]
        public void Close()
        {
            IDisposable _this = JitHelpers.UnsafeCast<IDisposable>(this);
            _this.Dispose();
        }
    }

    // Adapter class which converts IDisposable.Dispose calls into IClosable.Close
    [SecurityCritical]
    internal sealed class IClosableToIDisposableAdapter
    {
        private IClosableToIDisposableAdapter()
        {
            Contract.Assert(false, "This class is never instantiated");
        }

        [SecurityCritical]
        private void Dispose()
        {
            IClosable _this = JitHelpers.UnsafeCast<IClosable>(this);
            _this.Close();
        }
    }
}