It's code where warning arises:
public async Task<Metadata> GetFolderAsync(string strDirectoryPathName, dynamic varKnownFolder = null)
{
using (await _FolderPathToInfoMapSync.EnterAsync().ConfigureAwait(false))
{
Metadata objFolder;
string strPathName = strDirectoryPathName;
if (varKnownFolder == null)
{
objFolder = await _Storage.Client.Files.GetMetadataAsync(strPathName);
}
else
{
//Here warning arises
if (varKnownFolder != null) _FolderPathToInfoMap.Add(strDirectoryPathName, varKnownFolder);
else objFolder = null;
}
}
return objFolder;
}
I mean reason for this is a varKnownFolder in method signature, but I don't understand what is wrong here.
If your code enters the first else block it means that (varKnownFolder == null) was evaluated to false.
So the second check is useless as varKnownFolder could never be null in this block.
public async Task<Metadata> GetFolderAsync(string strDirectoryPathName, dynamic varKnownFolder = null)
{
using (await _FolderPathToInfoMapSync.EnterAsync().ConfigureAwait(false))
{
Metadata objFolder;
string strPathName = strDirectoryPathName;
if (varKnownFolder == null)
{
// This would happen if varKnownFolder is null
objFolder = await _Storage.Client.Files.GetMetadataAsync(strPathName);
}
else
{
// The code enters HERE BECAUSE varKnownFolder is not null
if (varKnownFolder != null) // <-- So this check is useless
_FolderPathToInfoMap.Add(strDirectoryPathName, varKnownFolder);
else
objFolder = null;
}
return objFolder;
}
}
Also, it means that you could replace it with this :
public async Task<Metadata> GetFolderAsync(string strDirectoryPathName, dynamic varKnownFolder = null)
{
using (await _FolderPathToInfoMapSync.EnterAsync().ConfigureAwait(false))
{
Metadata objFolder = null;
string strPathName = strDirectoryPathName;
if (varKnownFolder == null)
{
objFolder = await _Storage.Client.Files.GetMetadataAsync(strPathName);
}
else
{
// The code enters HERE BECAUSE varKnownFolder is not null
_FolderPathToInfoMap.Add(strDirectoryPathName, varKnownFolder);
}
return objFolder;
}
}
Because you are checking the inverse of the same condition within a block that has already been asserted by the outer if statement. Logically your code is the equivalent of...
if(x==false)
{
}
else // x must be true here
{
if(x==true) { }
}
if (varKnownFolder == null)
{
}
else
{
//You already know it is not null (because of the "if" check)
if (varKnownFolder != null)
}
Your "if" statement checks if you have a null object.
Inside your "else", varKnownFolder can't be null.
I mean reason for this is a varKnownFolder in method signature
Nope, the varKnownFolder = null inside method signature just means that, if you call this method without varKnownFolder, it will be null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With