Created
September 23, 2012 22:15
-
-
Save derans/3773235 to your computer and use it in GitHub Desktop.
Excel Column Definition Class
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
public class ExcelColumnDefinition | |
{ | |
public MemberInfo MemberInfo { get; set; } | |
public string Format { get; set; } | |
public string Header { get; set; } | |
public static ExcelColumnDefinition Create<T>(Expression<Func<T, object>> member, string format = null, string header = null) | |
{ | |
return new ExcelColumnDefinition { MemberInfo = GetMemberInfo(member), Format = format, Header = header }; | |
} | |
private static MemberInfo GetMemberInfo<T>(Expression<Func<T, object>> expression) | |
{ | |
if (expression.Body is MemberExpression) | |
return ((MemberExpression)expression.Body).Member; | |
return ((MemberExpression) ((UnaryExpression) expression.Body).Operand).Member; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment