GetExtension should return null in case it didn't find the extension
Closed this issue ยท 4 comments
This is not "mandatory" but would lead to a more friendly approach for a new user that comes across your package. Obviously, if the data is not found, you should never return a value (even if an empty string) as it may lead to strange behavior or misunderstanding.
I would highly recommend to introduce this breaking change in your library:
public static string GetExtension(string mimeType, bool throwErrorIfNotFound = true)
{
...
- return string.Empty;
+ return null;
}
In addition to this, I would recommend anyone making checks against a string to use the extension methods provided to that use:
I'm not going to introduce what could easily be a breaking change for everybody. Sorry. We are introducing a TryGetExtension
method in another PR which should satisfy your needs.
Can you link that pull request ? I'd like to take a look at the code. I don't see anything related to that but it's a good idea to introduce a TryGetExtension
too!
It's now been merged. Take a look at the updated code that includes TryGetExtension
. NuGet also updated.