Skip to content

Instantly share code, notes, and snippets.

@pdoran
Last active August 29, 2015 14:06
Show Gist options
  • Save pdoran/67f72bde17dd4fd85680 to your computer and use it in GitHub Desktop.
Save pdoran/67f72bde17dd4fd85680 to your computer and use it in GitHub Desktop.
//A book example
public string GetSomethingFromDBAndFormat(Guid id){
//Get item from DB
var obj = Session.Get<Something>(id);
var formatString = "";
//check if it is null
if(obj!=null) {
//add the name to return string
formatString += string.Format("Name: {0}",obj.Name);
//if it has children append names
if(obj.Children!=null && obj.Children.Count()>0) {
//loop over all children add append name
foreach(var child in obj.Children) {
//append child names if they aren't empty
if(!string.IsNullOrEmpty(child.Name)) {
//Add child format string
formatString += string.Format(" Child: Name: {0} ",child.Name);
}
}
}
}
return formatString.Trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment