Error in "Introduce variable" in Linq Expression?
Hi,
given the following code:
var signerAddresses = (from signer in Signers
where signer.Certificate != null
select
signer.Certificate.GetRfc822Name())
.ToList();
If I execute the "Introduce variable" action on
"signer.Certificate.GetRfc822Name()", the result is:
var signerAddresses = (from signer in Signers
let emailAddress =
signer.Certificate.GetRfc822Name()
where signer.Certificate != null
select emailAddress)
.ToList();
This may now lead to NullReferenceExceptions because the Null-Check for the
Certificate property is after the let command.
In my opinion, R# should insert the let on the line directly before the
select command:
var signerAddresses = (from signer in Signers
where signer.Certificate != null
let emailAddress = signer.Certificate.GetRfc822Name()
select emailAddress)
.ToList();
Kind regards,
Henning
Please sign in to leave a comment.
Hi,
Any comment on this?
Kind regards,
Henning Krause
"Henning Krause" wrote in message
news:isshva$c32$1@nntp-server.labs.intellij.net...
Hi,
given the following code:
var signerAddresses = (from signer in Signers
where signer.Certificate != null
select
signer.Certificate.GetRfc822Name())
.ToList();
If I execute the "Introduce variable" action on
"signer.Certificate.GetRfc822Name()", the result is:
var signerAddresses = (from signer in Signers
let emailAddress =
signer.Certificate.GetRfc822Name()
where signer.Certificate != null
select emailAddress)
.ToList();
This may now lead to NullReferenceExceptions because the Null-Check for the
Certificate property is after the let command.
In my opinion, R# should insert the let on the line directly before the
select command:
var signerAddresses = (from signer in Signers
where signer.Certificate != null
let emailAddress = signer.Certificate.GetRfc822Name()
select emailAddress)
.ToList();
Kind regards,
Henning