Skip to content

Instantly share code, notes, and snippets.

@keithbloom
Created September 20, 2011 14:01
Show Gist options
  • Save keithbloom/1229132 to your computer and use it in GitHub Desktop.
Save keithbloom/1229132 to your computer and use it in GitHub Desktop.
blog-post-using-iterators
private static IEnumerable<PropertyValue> GetProperties(object o)
{
if (o != null) {
var props = TypeDescriptor.GetProperties(o);
foreach (PropertyDescriptor prop in props) {
var val = prop.GetValue(o);
if (val != null) {
yield return new PropertyValue { Name = prop.Name, Value = val };
}
}
}
}
private sealed class PropertyValue
{
public string Name { get; set; }
public object Value { get; set; }
}
public class PaginationItem
{
public bool Active { get; set; }
public string Text { get; set; }
public string Url { get; set; }
}
private IEnumerable<PaginationItem> BuildList(int start, int end)
{
while(start <= end)
{
yield return new PaginationItem
{
Active = start == _page + 1,
Text = (start).ToString(),
Url = _UrlMaker(start - 1)
};
start++;
}
}
BuildList(start, end).ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment