Skip to content

Commit

Permalink
using (var stream = GetResourceAsStream (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH authored Sep 2, 2021
1 parent 9b03a39 commit 2b0d4d9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.0.12</VersionPrefix>
<VersionPrefix>1.0.13</VersionPrefix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion GitHubReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes

GitHubReleaseNotes.exe --output ReleaseNotes.md --skip-empty-releases --version 1.0.12.0
GitHubReleaseNotes.exe --output ReleaseNotes.md --skip-empty-releases --version 1.0.13
6 changes: 5 additions & 1 deletion src/ConsoleAppClassic/MainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static void Run()
string lipsum = randomizerTextLipsum.Generate();
Write(randomizerTextLipsum, lipsum);

var randomizerTextPattern = RandomizerFactory.GetRandomizer(new FieldOptionsTextPattern { Pattern = "\\xLLnn_**ss\\x" });
var randomizerTextPattern = RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = "\\xLLnn_**ss\\x" });
string textPattern = randomizerTextPattern.Generate();
Write(randomizerTextPattern, textPattern);

Expand All @@ -173,6 +173,10 @@ public static void Run()
var randomizerNaughtyStringsNullCategory = RandomizerFactory.GetRandomizer(new FieldOptionsTextNaughtyStrings());
string naughtyString2 = randomizerNaughtyStringsNullCategory.Generate();
Write(randomizerNaughtyStringsNullCategory, naughtyString2);

var randomizerEmail = RandomizerFactory.GetRandomizer(new FieldOptionsEmailAddress());
var email = randomizerEmail.Generate();
Write(randomizerEmail, email);
}

private static void Write<T>(object randomizer, T value)
Expand Down
26 changes: 15 additions & 11 deletions src/RandomDataGenerator/Data/ListData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace RandomDataGenerator.Data
{
internal sealed class ListData
{
private const char Tab = '\t';

public IEnumerable<string> LastNames { get; }

public IEnumerable<string> MaleNames { get; }
Expand All @@ -34,7 +36,7 @@ internal sealed class ListData

public IEnumerable<string> LoremIpsumWords { get; }

ListData()
private ListData()
{
LastNames = GetResourceAsLines("LastNames");
MaleNames = GetResourceAsLines("MaleNames");
Expand Down Expand Up @@ -65,30 +67,32 @@ static Nested()
internal static readonly ListData TextInstance = new ListData();
}

private Stream GetResourceAsStream(string resourceName)
private static Stream GetResourceAsStream(string resourceName)
{
return typeof(ListData).GetTypeInfo().Assembly.GetManifestResourceStream($"RandomDataGenerator.Data.Text.{resourceName}.txt");
}

private IEnumerable<string> GetResourceAsLines(string fileName)
private static IEnumerable<string> GetResourceAsLines(string fileName)
{
var stream = GetResourceAsStream(fileName);
using (var reader = new StreamReader(stream, Encoding.UTF8))
using (var stream = GetResourceAsStream(fileName))
{
string line;
while ((line = reader.ReadLine()) != null)
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
yield return line;
string line;
while ((line = reader.ReadLine()) != null)
{
yield return line;
}
}
}
}

private IEnumerable<T> GetResourceAsItems<T>(string fileName, Func<string[], T> convert)
private static IEnumerable<T> GetResourceAsItems<T>(string fileName, Func<string[], T> convert)
{
var lines = GetResourceAsLines(fileName);
foreach (string line in lines)
foreach (var line in lines)
{
yield return convert(line.Split('\t'));
yield return convert(line.Split(Tab));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/RandomDataGenerator/Data/Models/IBAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RandomDataGenerator.Data.Models
{
internal class IBAN
internal struct IBAN
{
public string CountryName { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/RandomDataGenerator/RandomDataGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2018.2.1">
<PackageReference Include="JetBrains.Annotations" Version="2021.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Fare" Version="2.1.1" />
<PackageReference Include="Fare" Version="2.1.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
Expand Down

0 comments on commit 2b0d4d9

Please sign in to comment.