Created
September 20, 2011 14:01
-
-
Save keithbloom/1229132 to your computer and use it in GitHub Desktop.
blog-post-using-iterators
This file contains hidden or 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
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; } | |
} |
This file contains hidden or 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
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