Skip to content

Instantly share code, notes, and snippets.

@armsteadj1
Created December 17, 2010 16:17
Show Gist options
  • Save armsteadj1/745193 to your computer and use it in GitHub Desktop.
Save armsteadj1/745193 to your computer and use it in GitHub Desktop.
// For you, what's the ideal conditional structure in this situation?
// Notes:
// Assume user.Job.Title comes from an outside system that we cannot control the format of (thus requiring the Trim)
binding.Name = showAliasName ? (user.AliasName != null && user.Job.Title != null && user.Job.Title.Trim().Length > 0 ? user.AliasName + " " + user.Job.Title : "N/A") : (user.Name != null && user.Job.Title != null && user.Job.Title.Trim().Length > 0 ? user.Name + " " + user.Job.Title : user.Name);
// Or
binding.Name = showAliasName
? (user.AliasName != null && user.Job.Title != null && user.Job.Title.Trim().Length > 0
? user.AliasName + " " + user.Job.Title
: "N/A")
: (user.Name != null && user.Job.Title != null && user.Job.Title.Trim().Length > 0
? user.Name + " " + user.Job.Title
: user.Name);
// Or
if (showAliasName)
{
if (user.AliasName != null && user.Job.Title != null && user.Job.Title.Trim().Length > 0)
{
binding.Name = user.AliasName + " " + user.Job.Title;
}
else
{
binding.Name = "N/A";
}
}
else
{
if (user.Name != null && user.Job.Title != null && user.Job.Title.Trim().Length > 0)
{
binding.Name = user.Name + " " + user.Job.Title;
}
else
{
binding.Name = user.Name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment