Issue with Convert to '??' expression

Hello

I have the following code:

public ProductComparerService() : this(null)

{

}

 

public ProductComparerService(ILogger logger)

{

    this.InitializeLogger(logger);

    this.InitializeServiceLocator();

    this.InitializeComponent();

}

 

private void InitializeLogger(ILogger logger)

{

    if (logger == null)

    {

        this._logger = new FileLogger();

    }

    else

    {

        this._logger = logger;

    }

}

ReSharper suggests to convert the if-statement to "??" expression and this results in an incorrect InitializeLogger() method:

private void InitializeLogger(ILogger logger)

{

    this._logger = new FileLogger() ?? logger;

}

Please sign in to leave a comment.