I understand Jeremy, but what if we change the ColumnBuilder method
"public IGridColumn<T> For(Expression<Func<T, object>>
propertySpecifier)" as bellow?
public IGridColumn<T> For(Expression<Func<T, object>>
propertySpecifier)
{
var memberExpression = GetMemberExpression(propertySpecifier);
var type = GetTypeFromMemberExpression(memberExpression);
var inferredName = memberExpression == null ? null :
memberExpression.ToString().Substring(
memberExpression.ToString().IndexOf(
propertySpecifier.Parameters[0].Name + ".") +
propertySpecifier.Parameters[0].Name.Length + 1);
var column = new GridColumn<T>(propertySpecifier.Compile(),
inferredName, type);
_columns.Add(column);
return column;
}
I runned all the test cases and all gone green, only the test
Should_infer_column_name_from_lambda in ColumnBuilderTester I changed
to expect "DateOfBirth.Day".
I think use the parameter[0] is not a problem as in this case we will
only have one parameter always.
Can you see another issue where i can't use this approach?
Thankx for the help!
Marcus
On Dec 14, 6:46 pm, Jeremy Skinner <
jer...@jeremyskinner.co.uk> wrote:
> I'm afraid this isn't currently possible. The ColumnBuilder always infers
> the name of the column based on the "Name" property of the MemberExpression.
> Based on an expression of x => x.DateOfBirth.Day, this will always return
> "Day". If you need to specify a custom column name, you'll need to use the
> .Named() method.
>
> Jeremy
>
> 2009/12/14 Marcus Rehm <
marcus.r...@gmail.com>
>
> > Hi,
>
> > There is a way to set the ColumnBuilder to infer the name of the
> > column with the "full name" like bellow?
> > If I set:
> > _builder.For(x => x.DateOfBirth.Day);
> > _builder.Single().Name.ShouldEqual("DateOfBirth.Day");
>
> > In the actual implementation _builder.For(x => x.DateOfBirth.Day)
> > infer the name as "Day".
> > Other situation is when I call:
> > _builder.For(x => x.Name);
> > _builder.For(x =>
x.Address.Street.Name);
> > Both columns has the same name "Name";
>
> > I'm working on a grid render for jqGrid and when i'm posting the data
> > for sorting, i can't get the right column. The other point is that if
> > the name inferred was "DateOfBirth.Day" it can be passed as it is to
> > the sort expression on Linq.
>
> > Thankx in advance!
>
> > --
> > Contact Jeffrey Palermo or Eric Hexter with specific questions about the
> > MvcContrib project. Or go tohttp://
mvccontrib.org