Initial commit
[mono.git] / mcs / class / referencesource / mscorlib / microsoft / win32 / safehandles / safefilehandle.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 /*============================================================
7 **
8 ** Class:  SafeFileHandle 
9 **
10 **
11 ** A wrapper for file handles
12 **
13 ** 
14 ===========================================================*/
15
16 using System;
17 using System.Security;
18 using System.Security.Permissions;
19 using System.Runtime.InteropServices;
20 using System.Runtime.CompilerServices;
21 using System.Runtime.ConstrainedExecution;
22 using System.Runtime.Versioning;
23 using Microsoft.Win32;
24
25 namespace Microsoft.Win32.SafeHandles {
26
27     [System.Security.SecurityCritical]  // auto-generated_required
28     public sealed class SafeFileHandle: SafeHandleZeroOrMinusOneIsInvalid {
29
30         private SafeFileHandle() : base(true) 
31         {
32         }
33
34         public SafeFileHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) {
35             SetHandle(preexistingHandle);
36         }
37
38         [System.Security.SecurityCritical]
39         [ResourceExposure(ResourceScope.Machine)]
40         [ResourceConsumption(ResourceScope.Machine)]
41         override protected bool ReleaseHandle()
42         {
43             return Win32Native.CloseHandle(handle);
44         }
45     }
46 }
47