New feature request

I have this block of code:

public string GetUserName()
{
IUserIdentity user = GetUser();
return ^user.Name;
}

When i have placed cursor where is ^, then quick fix tooltip show me:
Check if 'user' is null

If would be nice if in such scenario can offer to me action which will
make this code:

return user != null ? user.Name : string.Empty;

--
Peter Sulek
terrorix@centrum.sk
XanaNews ver. 1.18.1.6

2 comments
Comment actions Permalink

Peter Sulek wrote:

I have this block of code:

public string GetUserName()
{
IUserIdentity user = GetUser();
return ^user.Name;
}

When i have placed cursor where is ^, then quick fix tooltip show me:
Check if 'user' is null

If would be nice if in such scenario can offer to me action which will
make this code:

return user != null ? user.Name : string.Empty;


Forgot to mention:
r# 4 build from 4.3.2008

--
Peter Sulek
terrorix@centrum.sk
XanaNews ver. 1.18.1.6

0
Comment actions Permalink

How would it know to use string.Empty, rather than null (default for strings) or "Unknown"?
Either of these are valid choices when user is null?
Also, if you do get it to put a check for null in, then you can put in another return statement, and then R# will offer to do what you want it to do.

public string GetUserName()
{
IUserIdentity user = GetUser();
if^ ( user != null )
return user.Name;
return string.Empty
}

0

Please sign in to leave a comment.