Follow try standard by DaveTryon · Pull Request #1121 · microsoft/sbom-tool (original) (raw)
I can't pin down documentation on this, but all of .NET Try* methods that use an out parameter follow the same pattern:
- If the method returns true, the
outparameter is notnull - If the method returns false, the
outparameter isnull
I happened to notice that the TryGetSbomsWithVersion method in SPDXFormatDetector was not following this pattern on failure--instead of setting detectedSboms to null, it was setting it to an empty list. This PR just sets detectedSboms to null on failure and updates the unit tests accordingly. The calling code didn't need any modification, since it was already checking the return value before using detectedSboms