Merge pull request #3528 from BrzVlad/fix-sgen-check-before-collections
[mono.git] / mcs / class / Facades / System.IO.FileSystem.AccessControl / FileSystemAclExtensions.cs
1 //
2 // FileSystemAclExtensions.cs
3 //
4 // Author:
5 //   Alexander Köplinger (alexander.koeplinger@xamarin.com)
6 //
7 // (C) 2016 Xamarin, Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Security.AccessControl;
32
33 namespace System.IO
34 {
35         public static class FileSystemAclExtensions
36         {
37                 public static DirectorySecurity GetAccessControl(this DirectoryInfo directoryInfo)
38                 {
39                         if (directoryInfo == null)
40                                 throw new ArgumentNullException (nameof (directoryInfo));
41
42                         return directoryInfo.GetAccessControl ();
43                 }
44
45                 public static DirectorySecurity GetAccessControl(this DirectoryInfo directoryInfo, AccessControlSections includeSections)
46                 {
47                         if (directoryInfo == null)
48                                 throw new ArgumentNullException (nameof (directoryInfo));
49
50                         return directoryInfo.GetAccessControl (includeSections);
51                 }
52
53                 public static FileSecurity GetAccessControl(this FileInfo fileInfo)
54                 {
55                         if (fileInfo == null)
56                                 throw new ArgumentNullException (nameof (fileInfo));
57
58                         return fileInfo.GetAccessControl ();
59                 }
60
61                 public static FileSecurity GetAccessControl(this FileInfo fileInfo, AccessControlSections includeSections)
62                 {
63                         if (fileInfo == null)
64                                 throw new ArgumentNullException (nameof (fileInfo));
65
66                         return fileInfo.GetAccessControl (includeSections);
67                 }
68
69                 public static FileSecurity GetAccessControl(this FileStream fileStream)
70                 {
71                         if (fileStream == null)
72                                 throw new ArgumentNullException (nameof (fileStream));
73
74                         return fileStream.GetAccessControl ();
75                 }
76
77                 public static void SetAccessControl(this DirectoryInfo directoryInfo, DirectorySecurity directorySecurity)
78                 {
79                         if (directoryInfo == null)
80                                 throw new ArgumentNullException (nameof (directoryInfo));
81
82                         directoryInfo.SetAccessControl (directorySecurity);
83                 }
84
85                 public static void SetAccessControl(this FileInfo fileInfo, FileSecurity fileSecurity)
86                 {
87                         if (fileInfo == null)
88                                 throw new ArgumentNullException (nameof (fileInfo));
89
90                         fileInfo.SetAccessControl (fileSecurity);
91                 }
92
93                 public static void SetAccessControl(this FileStream fileStream, FileSecurity fileSecurity)
94                 {
95                         if (fileStream == null)
96                                 throw new ArgumentNullException (nameof (fileStream));
97
98                         fileStream.SetAccessControl (fileSecurity);
99                 }
100         }
101 }