Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 643a396

Browse files
authored
Move platform-neutral part of TimeZone to shared CoreLib partition (#15926)
Prep work for moving the platform specific parts
1 parent 516b973 commit 643a396

9 files changed

+67
-101
lines changed

src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@
347347
<Compile Include="$(BclSourcesRoot)\System\RuntimeHandles.cs" />
348348
<Compile Include="$(BclSourcesRoot)\System\SharedStatics.cs" />
349349
<Compile Include="$(BclSourcesRoot)\System\StubHelpers.cs" />
350-
<Compile Include="$(BclSourcesRoot)\System\TimeZoneInfo.AdjustmentRule.cs" />
351-
<Compile Include="$(BclSourcesRoot)\System\TimeZoneInfo.cs" />
352-
<Compile Include="$(BclSourcesRoot)\System\TimeZoneInfo.StringSerializer.cs" />
353-
<Compile Include="$(BclSourcesRoot)\System\TimeZoneInfo.TransitionTime.cs" />
354350
<Compile Include="$(BclSourcesRoot)\System\Type.CoreCLR.cs" />
355351
<Compile Include="$(BclSourcesRoot)\System\TypeNameParser.cs" />
356352
<Compile Include="$(BclSourcesRoot)\System\TypedReference.cs" />

src/mscorlib/shared/System.Private.CoreLib.Shared.projitems

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@
551551
<Compile Include="$(MSBuildThisFileDirectory)System\ThreadStaticAttribute.cs" />
552552
<Compile Include="$(MSBuildThisFileDirectory)System\TimeoutException.cs" />
553553
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZone.cs" />
554+
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.cs" />
555+
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.AdjustmentRule.cs" />
556+
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.StringSerializer.cs" />
557+
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.TransitionTime.cs" />
554558
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneNotFoundException.cs" />
555559
<Compile Include="$(MSBuildThisFileDirectory)System\Tuple.cs" />
556560
<Compile Include="$(MSBuildThisFileDirectory)System\TupleExtensions.cs" />
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/mscorlib/src/System/IO/File.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,34 +107,6 @@ public static byte[] ReadAllBytes(String path)
107107
return bytes;
108108
}
109109

110-
#if PLATFORM_UNIX
111-
public static String[] ReadAllLines(String path)
112-
{
113-
if (path == null)
114-
throw new ArgumentNullException(nameof(path));
115-
if (path.Length == 0)
116-
throw new ArgumentException(SR.Argument_EmptyPath);
117-
118-
return InternalReadAllLines(path, Encoding.UTF8);
119-
}
120-
121-
private static String[] InternalReadAllLines(String path, Encoding encoding)
122-
{
123-
Debug.Assert(path != null);
124-
Debug.Assert(encoding != null);
125-
Debug.Assert(path.Length != 0);
126-
127-
String line;
128-
List<String> lines = new List<String>();
129-
130-
using (StreamReader sr = new StreamReader(path, encoding))
131-
while ((line = sr.ReadLine()) != null)
132-
lines.Add(line);
133-
134-
return lines.ToArray();
135-
}
136-
#endif // PLATFORM_UNIX
137-
138110
// Returns 0 on success, otherwise a Win32 error code. Note that
139111
// classes should use -1 as the uninitialized state for dataInitialized.
140112
internal static int FillAttributeInfo(String path, ref Win32Native.WIN32_FILE_ATTRIBUTE_DATA data, bool tryagain, bool returnErrorOnNotFound)

src/mscorlib/src/System/TimeZoneInfo.Unix.cs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -241,54 +241,50 @@ private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachine(string id, out
241241
/// </remarks>
242242
private static List<string> GetTimeZoneIds(string timeZoneDirectory)
243243
{
244-
string[] zoneTabFileLines = null;
245-
try
246-
{
247-
zoneTabFileLines = File.ReadAllLines(Path.Combine(timeZoneDirectory, ZoneTabFileName));
248-
}
249-
catch (IOException) { }
250-
catch (UnauthorizedAccessException) { }
244+
List<string> timeZoneIds = new List<string>();
251245

252-
if (zoneTabFileLines == null)
253-
{
254-
return new List<string>();
255-
}
256-
257-
List<string> timeZoneIds = new List<string>(zoneTabFileLines.Length);
258-
259-
foreach (string zoneTabFileLine in zoneTabFileLines)
246+
try
260247
{
261-
if (!string.IsNullOrEmpty(zoneTabFileLine) && zoneTabFileLine[0] != '#')
248+
using (StreamReader sr = new StreamReader(Path.Combine(timeZoneDirectory, ZoneTabFileName), Encoding.UTF8))
262249
{
263-
// the format of the line is "country-code \t coordinates \t TimeZone Id \t comments"
264-
265-
int firstTabIndex = zoneTabFileLine.IndexOf('\t');
266-
if (firstTabIndex != -1)
250+
string zoneTabFileLine;
251+
while ((zoneTabFileLine = sr.ReadLine()) != null)
267252
{
268-
int secondTabIndex = zoneTabFileLine.IndexOf('\t', firstTabIndex + 1);
269-
if (secondTabIndex != -1)
253+
if (!string.IsNullOrEmpty(zoneTabFileLine) && zoneTabFileLine[0] != '#')
270254
{
271-
string timeZoneId;
272-
int startIndex = secondTabIndex + 1;
273-
int thirdTabIndex = zoneTabFileLine.IndexOf('\t', startIndex);
274-
if (thirdTabIndex != -1)
275-
{
276-
int length = thirdTabIndex - startIndex;
277-
timeZoneId = zoneTabFileLine.Substring(startIndex, length);
278-
}
279-
else
280-
{
281-
timeZoneId = zoneTabFileLine.Substring(startIndex);
282-
}
255+
// the format of the line is "country-code \t coordinates \t TimeZone Id \t comments"
283256

284-
if (!string.IsNullOrEmpty(timeZoneId))
257+
int firstTabIndex = zoneTabFileLine.IndexOf('\t');
258+
if (firstTabIndex != -1)
285259
{
286-
timeZoneIds.Add(timeZoneId);
260+
int secondTabIndex = zoneTabFileLine.IndexOf('\t', firstTabIndex + 1);
261+
if (secondTabIndex != -1)
262+
{
263+
string timeZoneId;
264+
int startIndex = secondTabIndex + 1;
265+
int thirdTabIndex = zoneTabFileLine.IndexOf('\t', startIndex);
266+
if (thirdTabIndex != -1)
267+
{
268+
int length = thirdTabIndex - startIndex;
269+
timeZoneId = zoneTabFileLine.Substring(startIndex, length);
270+
}
271+
else
272+
{
273+
timeZoneId = zoneTabFileLine.Substring(startIndex);
274+
}
275+
276+
if (!string.IsNullOrEmpty(timeZoneId))
277+
{
278+
timeZoneIds.Add(timeZoneId);
279+
}
280+
}
287281
}
288282
}
289283
}
290284
}
291285
}
286+
catch (IOException) { }
287+
catch (UnauthorizedAccessException) { }
292288

293289
return timeZoneIds;
294290
}

0 commit comments

Comments
 (0)