File tree 2 files changed +15
-28
lines changed 2 files changed +15
-28
lines changed Original file line number Diff line number Diff line change 3
3
using System . Collections . Generic ;
4
4
using System . IO ;
5
5
using System . Reflection ;
6
- using System . Text ;
7
6
8
7
namespace DataStructures . Common
9
8
{
@@ -65,7 +64,8 @@ public static PrimesList Instance
65
64
/// </summary>
66
65
private static void _initializeData ( )
67
66
{
68
- string [ ] lines = _readResource ( "DataStructures.Data.PrimesDocument_10K.csv" ) ;
67
+ _primesDocPath = Path . Combine ( Path . GetDirectoryName ( typeof ( PrimesList ) . GetTypeInfo ( ) . Assembly . Location ) , @"Data/PrimesDocument_10K.csv" ) ;
68
+ string [ ] lines = File . ReadAllLines ( _primesDocPath ) ;
69
69
70
70
foreach ( var line in lines )
71
71
{
@@ -84,28 +84,10 @@ private static void _initializeData()
84
84
}
85
85
}
86
86
87
- /// <summary>
88
- /// Reads an embedded resource as a text file.
89
- /// </summary>
90
- /// <returns></returns>
91
- public static string [ ] _readResource ( string resourceName )
92
- {
93
- try
94
- {
95
- using ( var stream = typeof ( PrimesList ) . GetTypeInfo ( ) . Assembly . GetManifestResourceStream ( resourceName ) )
96
- using ( var reader = new StreamReader ( stream ?? throw new InvalidOperationException ( "Failed to read resource" ) , Encoding . UTF8 ) )
97
- return reader . ReadToEnd ( ) . Split ( "\r \n " ) ;
98
- }
99
- catch ( Exception ex )
100
- {
101
- throw new Exception ( $ "Failed to read resource { resourceName } ", ex ) ;
102
- }
103
- }
104
-
105
- /// <summary>
106
- /// Return count of primes.
107
- /// </summary>
108
- public int Count
87
+ /// <summary>
88
+ /// Return count of primes.
89
+ /// </summary>
90
+ public int Count
109
91
{
110
92
get { return _primes . Count ; }
111
93
}
@@ -228,4 +210,5 @@ public void CopyTo(int[] array, int index = 0)
228
210
}
229
211
230
212
}
213
+
231
214
}
Original file line number Diff line number Diff line change 2
2
<PropertyGroup >
3
3
<TargetFramework >netcoreapp2.0</TargetFramework >
4
4
</PropertyGroup >
5
+
5
6
<ItemGroup >
6
- <None Remove =" Data\PrimesDocument_10K.csv" />
7
+ <Content Include =" Data\PrimesDocument_10K.csv" >
8
+ <CopyToOutputDirectory >Always</CopyToOutputDirectory >
9
+ </Content >
7
10
</ItemGroup >
11
+
8
12
<ItemGroup >
9
- <EmbeddedResource Include =" Data\PrimesDocument_10K.csv" >
10
- <CopyToOutputDirectory >Never </CopyToOutputDirectory >
11
- </EmbeddedResource >
13
+ <None Update =" Data\PrimesDocument_10K.csv" >
14
+ <CopyToOutputDirectory >Always </CopyToOutputDirectory >
15
+ </None >
12
16
</ItemGroup >
13
17
</Project >
You can’t perform that action at this time.
0 commit comments