Skip to content

Commit 6d13d07

Browse files
committed
Fix net48 build again
1 parent 763bfc0 commit 6d13d07

File tree

4 files changed

+62
-44
lines changed

4 files changed

+62
-44
lines changed

src/libraries/System.Private.CoreLib/src/System/IO/File.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static StreamWriter AppendText(string path)
5252
return new StreamWriter(path, append: true);
5353
}
5454

55+
#if NET6_0_OR_GREATER
5556
public static StreamReader OpenText(string path, FileStreamOptions options)
5657
{
5758
if (path == null)
@@ -94,6 +95,7 @@ private static FileStreamOptions Override(FileStreamOptions options, FileMode? f
9495
PreallocationSize = options.PreallocationSize
9596
};
9697
}
98+
#endif
9799

98100
/// <summary>
99101
/// Copies an existing file to a new file.
@@ -140,8 +142,10 @@ public static FileStream Create(string path, int bufferSize)
140142
public static FileStream Create(string path, int bufferSize, FileOptions options)
141143
=> new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize, options);
142144

145+
#if NET6_0_OR_GREATER
143146
public static FileStream Create(string path, FileStreamOptions options)
144147
=> new FileStream(path, Override(options, FileMode.Create));
148+
#endif
145149

146150
// Deletes a file. The file specified by the designated path is deleted.
147151
// If the file does not exist, Delete succeeds without throwing
@@ -205,10 +209,12 @@ public static FileStream Open(string path, FileMode mode, FileAccess access, Fil
205209
return new FileStream(path, mode, access, share);
206210
}
207211

212+
#if NET6_0_OR_GREATER
208213
public static FileStream Open(string path, FileMode mode, FileStreamOptions options)
209214
{
210215
return new FileStream(path, Override(options, mode));
211216
}
217+
#endif
212218

213219
internal static DateTimeOffset GetUtcDateTimeOffset(DateTime dateTime)
214220
{
@@ -316,6 +322,7 @@ public static FileStream OpenWrite(string path)
316322
return new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
317323
}
318324

325+
#if NET6_0_OR_GREATER
319326
public static FileStream OpenRead(string path, FileStreamOptions options)
320327
{
321328
return new FileStream(path, Override(options, FileMode.Open, FileAccess.Read));
@@ -325,6 +332,7 @@ public static FileStream OpenWrite(string path, FileStreamOptions options)
325332
{
326333
return new FileStream(path, Override(options, FileMode.OpenOrCreate, FileAccess.Write));
327334
}
335+
#endif
328336

329337
public static string ReadAllText(string path)
330338
{

src/libraries/System.Private.CoreLib/src/System/IO/FileInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public StreamWriter CreateText()
8585
public StreamWriter AppendText()
8686
=> new StreamWriter(NormalizedPath, append: true);
8787

88+
#if NET6_0_OR_GREATER
8889
public StreamReader OpenText(FileStreamOptions options)
8990
=> File.OpenText(NormalizedPath, options);
9091

@@ -93,6 +94,7 @@ public StreamWriter CreateText(FileStreamOptions options)
9394

9495
public StreamWriter AppendText(FileStreamOptions options)
9596
=> File.AppendText(NormalizedPath, options);
97+
#endif
9698

9799
public FileInfo CopyTo(string destFileName) => CopyTo(destFileName, overwrite: false);
98100

@@ -115,12 +117,14 @@ public FileStream Create()
115117
return fileStream;
116118
}
117119

120+
#if NET6_0_OR_GREATER
118121
public FileStream Create(FileStreamOptions options)
119122
{
120123
FileStream fileStream = File.Create(NormalizedPath, options);
121124
Invalidate();
122125
return fileStream;
123126
}
127+
#endif
124128

125129
public override void Delete()
126130
{
@@ -143,6 +147,7 @@ public FileStream OpenRead()
143147
public FileStream OpenWrite()
144148
=> new FileStream(NormalizedPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
145149

150+
#if NET6_0_OR_GREATER
146151
public FileStream Open(FileMode mode, FileStreamOptions options)
147152
=> File.Open(NormalizedPath, mode, options);
148153

@@ -151,6 +156,7 @@ public FileStream OpenRead(FileStreamOptions options)
151156

152157
public FileStream OpenWrite(FileStreamOptions options)
153158
=> File.OpenRead(NormalizedPath, options);
159+
#endif
154160

155161
// Moves a given file to a new location and potentially a new file name.
156162
// This method does work across volumes.

src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ public StreamReader(string path)
178178
{
179179
}
180180

181-
public StreamReader(string path, FileStreamOptions options)
182-
: this(path, Encoding.UTF8, true, options)
183-
{
184-
}
185-
186181
public StreamReader(string path, bool detectEncodingFromByteOrderMarks)
187182
: this(path, Encoding.UTF8, detectEncodingFromByteOrderMarks, DefaultBufferSize)
188183
{
@@ -198,26 +193,32 @@ public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteO
198193
{
199194
}
200195

201-
public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, FileStreamOptions options)
202-
: this(ValidateArgsAndOpenPath(path, encoding, options), encoding, detectEncodingFromByteOrderMarks, DefaultBufferSize)
196+
public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)
197+
: this(ValidateArgsAndOpenPath(path, encoding, bufferSize), encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen: false)
203198
{
204199
}
205200

206-
public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)
207-
: this(ValidateArgsAndOpenPath(path, encoding, bufferSize), encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen: false)
201+
#if NET6_0_OR_GREATER
202+
public StreamReader(string path, FileStreamOptions options)
203+
: this(path, Encoding.UTF8, true, options)
208204
{
209205
}
210206

211-
private static void ValidateArgs(string path, Encoding encoding)
207+
public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, FileStreamOptions options)
208+
: this(ValidateArgsAndOpenPath(path, encoding, options), encoding, detectEncodingFromByteOrderMarks, DefaultBufferSize)
212209
{
213-
if (path == null)
214-
throw new ArgumentNullException(nameof(path));
215-
if (encoding == null)
216-
throw new ArgumentNullException(nameof(encoding));
217-
if (path.Length == 0)
218-
throw new ArgumentException(SR.Argument_EmptyPath);
219210
}
220211

212+
private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, FileStreamOptions options)
213+
{
214+
ValidateArgs(path, encoding);
215+
if (options == null)
216+
throw new ArgumentNullException(nameof(options));
217+
218+
return new FileStream(path, options);
219+
}
220+
#endif
221+
221222
private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, int bufferSize)
222223
{
223224
ValidateArgs(path, encoding);
@@ -227,13 +228,14 @@ private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, in
227228
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultFileStreamBufferSize);
228229
}
229230

230-
private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, FileStreamOptions options)
231+
private static void ValidateArgs(string path, Encoding encoding)
231232
{
232-
ValidateArgs(path, encoding);
233-
if (options == null)
234-
throw new ArgumentNullException(nameof(options));
235-
236-
return new FileStream(path, options);
233+
if (path == null)
234+
throw new ArgumentNullException(nameof(path));
235+
if (encoding == null)
236+
throw new ArgumentNullException(nameof(encoding));
237+
if (path.Length == 0)
238+
throw new ArgumentException(SR.Argument_EmptyPath);
237239
}
238240

239241
public override void Close()

src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ public StreamWriter(string path)
139139
{
140140
}
141141

142-
public StreamWriter(string path, FileStreamOptions options)
143-
: this(path, UTF8NoBOM, options)
144-
{
145-
}
146-
147142
public StreamWriter(string path, bool append)
148143
: this(path, append, UTF8NoBOM, DefaultBufferSize)
149144
{
@@ -154,26 +149,32 @@ public StreamWriter(string path, bool append, Encoding encoding)
154149
{
155150
}
156151

157-
public StreamWriter(string path, Encoding encoding, FileStreamOptions options)
158-
: this(ValidateArgsAndOpenPath(path, encoding, options), encoding, DefaultFileStreamBufferSize)
152+
public StreamWriter(string path, bool append, Encoding encoding, int bufferSize) :
153+
this(ValidateArgsAndOpenPath(path, append, encoding, bufferSize), encoding, bufferSize, leaveOpen: false)
159154
{
160155
}
161156

162-
public StreamWriter(string path, bool append, Encoding encoding, int bufferSize) :
163-
this(ValidateArgsAndOpenPath(path, append, encoding, bufferSize), encoding, bufferSize, leaveOpen: false)
157+
#if NET6_0_OR_GREATER
158+
public StreamWriter(string path, FileStreamOptions options)
159+
: this(path, UTF8NoBOM, options)
164160
{
165161
}
166162

167-
private static void ValidateArgs(string path, Encoding encoding)
163+
public StreamWriter(string path, Encoding encoding, FileStreamOptions options)
164+
: this(ValidateArgsAndOpenPath(path, encoding, options), encoding, DefaultFileStreamBufferSize)
168165
{
169-
if (path == null)
170-
throw new ArgumentNullException(nameof(path));
171-
if (encoding == null)
172-
throw new ArgumentNullException(nameof(encoding));
173-
if (path.Length == 0)
174-
throw new ArgumentException(SR.Argument_EmptyPath);
175166
}
176167

168+
private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, FileStreamOptions options)
169+
{
170+
ValidateArgs(path, encoding);
171+
if (options == null)
172+
throw new ArgumentNullException(nameof(options));
173+
174+
return new FileStream(path, options);
175+
}
176+
#endif
177+
177178
private static Stream ValidateArgsAndOpenPath(string path, bool append, Encoding encoding, int bufferSize)
178179
{
179180
ValidateArgs(path, encoding);
@@ -183,13 +184,14 @@ private static Stream ValidateArgsAndOpenPath(string path, bool append, Encoding
183184
return new FileStream(path, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read, DefaultFileStreamBufferSize);
184185
}
185186

186-
private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, FileStreamOptions options)
187+
private static void ValidateArgs(string path, Encoding encoding)
187188
{
188-
ValidateArgs(path, encoding);
189-
if (options == null)
190-
throw new ArgumentNullException(nameof(options));
191-
192-
return new FileStream(path, options);
189+
if (path == null)
190+
throw new ArgumentNullException(nameof(path));
191+
if (encoding == null)
192+
throw new ArgumentNullException(nameof(encoding));
193+
if (path.Length == 0)
194+
throw new ArgumentException(SR.Argument_EmptyPath);
193195
}
194196

195197
public override void Close()

0 commit comments

Comments
 (0)