Skip to content

Commit

Permalink
Throwing Exception from Utility Function
Browse files Browse the repository at this point in the history
  • Loading branch information
kruplm committed Jul 4, 2023
1 parent 5196196 commit 96df7c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
19 changes: 8 additions & 11 deletions src/shell/dotnet/Shell/Utilities/ResourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,21 @@ namespace Shell.Utilities
{
public static class ResourceReader
{
public static string ReadResource(string name)
public static string ReadResource(string name)
{
var assembly = Assembly.GetExecutingAssembly();
string resourcePath = name;
try

var stream = assembly.GetManifestResourceStream(resourcePath);

if (stream == null)
{
using (var stream = assembly.GetManifestResourceStream(resourcePath))
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
throw new InvalidOperationException("Resource not found");
}
catch
using (var reader = new StreamReader(stream))
{
return null;
return reader.ReadToEnd();
}


}
}
}
8 changes: 0 additions & 8 deletions src/shell/dotnet/tests/Shell.Tests/ResourceReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ namespace ShellTests
{
public class ReadResourceTests
{
[Fact]
public void ResourceNotAvailable()
{
var resource = ResourceReader.ReadResource("NotAvailableResource");

Assert.Null(resource);
}

[Fact]
public void ResourceCanBeRead()
{
Expand Down

0 comments on commit 96df7c8

Please sign in to comment.