Describe the bug
The implementations for FileInfoFactory.Wrap and DirectoryInfoFactory.Wrap require non-null references, while the interfaces are defined as [return: NotNullIfNotNull("fileInfo")] IFileInfoFactory.Wrap(FileInfo? fileInfo) and likewise for IDirectoryInfoFactory.Wrap.
To Reproduce
Steps to reproduce the behavior:
new FileSystem().FileInfo.Wrap(null);- The analyzer and compiler accept the syntax since
IFileInfoFactory.Wrap accepts FileInfo? and returns IFileInfo? - An
ArgumentNullException is thrown
Expected behavior
I expect to get a nullIFileInfo? back if the input is null, and no exception thrown.
Additional context
Fixing this will help compatibility with System.CommandLine where defining options as FileInfo? is a common practice, i.e.:
varinputFileOption=newOption<FileInfo?>("--input");varcommand=newCommand("test"){inputFileOption};command.SetHandler((FileInfo?inputFile)=>{varfileSystem=newFileSystem();varconcreteCommand=newConcreteCommand(fileSystem:fileSystem){InputFile=fileSystem.FileInfo.Wrap(inputFile)}
concreteCommand.Run();},inputFileOption);
Describe the bug
The implementations for
FileInfoFactory.WrapandDirectoryInfoFactory.Wraprequire non-null references, while the interfaces are defined as[return: NotNullIfNotNull("fileInfo")] IFileInfoFactory.Wrap(FileInfo? fileInfo)and likewise forIDirectoryInfoFactory.Wrap.To Reproduce
Steps to reproduce the behavior:
new FileSystem().FileInfo.Wrap(null);IFileInfoFactory.WrapacceptsFileInfo?and returnsIFileInfo?ArgumentNullExceptionis thrownExpected behavior
I expect to get a
nullIFileInfo?back if the input isnull, and no exception thrown.Additional context
Fixing this will help compatibility with System.CommandLine where defining options as
FileInfo?is a common practice, i.e.: