c# - Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions -
error line;
modelmetadata metadata = modelmetadata.fromlambdaexpression<t, object>(columnproperty, phtml.viewdata);
model
public class menuauths : entitybase { [bsonignoreifnull] [bsonrepresentation(bsontype.objectid)] public string menuid { get; set; } [bsondefaultvalue(false)] public bool allownew { get; set; } }
cshtml;
new column<lsdatamodels.menuauths> { columnproperty = c => c.menuid }, new column<lsdatamodels.menuauths> { columnproperty = c => c.allownew},
this line work new column<lsdatamodels.menuauths> { columnproperty = c => c.menuid }
line have error new column<lsdatamodels.menuauths> { columnproperty = c => c.allownew},
i can try property type change bool?
, bool
, nulable<bool>
error has been continue. remove [bsondefaultvalue(false)]
attribute nothing change.
what can do?
edit: error templates can used field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
i find solition problem.
i use propertyinfo
i add exdent method on expression<func<t, dynamic>>
public static propertyinfo getproperty<t>(this expression<func<t, dynamic>> expression) { memberexpression memberexpression = null; if (expression.body.nodetype == expressiontype.convert) { memberexpression = ((unaryexpression)expression.body).operand memberexpression; } else if (expression.body.nodetype == expressiontype.memberaccess) { memberexpression = expression.body memberexpression; } if (memberexpression == null) { throw new argumentexception("not member access", "expression"); } return memberexpression.member propertyinfo; }
and change line
modelmetadata metadata = modelmetadata.fromlambdaexpression<t, object>(columnproperty, phtml.viewdata);
to
propertyinfo pi = fieldproperty.getproperty<t>();
i can access need attributes , properties on propertyinfo
Comments
Post a Comment