Last active
August 29, 2015 14:06
-
-
Save pdoran/67f72bde17dd4fd85680 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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