format : (string columnName, DynamicRecord row) => @Html.Link(name : "", text : (string)row[columnName], action : "modify.cshtml",
parameters : new { l = Request["l"], id = row["id"], lt = Page.Language, p = Request["p"] }
)
that provides a formatting template to print some contents in a cell of a table. no problems, it works.
as this code could be more complex and reused in many places i was thinking to trasform it in a function to write just
format : MyFormattingTemplate("modify.cshtml",
parameters : new { l = Request["l"], id = row["id"], lt = Page.Language, p = Request["p"] }
)
i can create MyFormattingTemplate to return a proper function and have the code working. i have only one problem:
id = row["id"]
that should be computed for every row. so, i searched a bit with no results, made same experiments... thought to encapsulate a lamba in an object this way
format : MyFormattingTemplate("modify.cshtml",
parameters : new { l = Request["l"], id = new MyParameter((string columnName, DynamicRecord row) => row["id]), lt = Page.Language, p = Request["p"] }
)
and compute the parameter in MyFormattingTemplate calling a method of MyParameter.
_pietro
Member
17 Points
58 Posts
[C# student] about transforming a lamba expression in a function
Dec 26, 2012 08:39 AM|LINK
c# and webmatrix... i have this piece of code
format : (string columnName, DynamicRecord row) => @Html.Link(name : "", text : (string)row[columnName], action : "modify.cshtml", parameters : new { l = Request["l"], id = row["id"], lt = Page.Language, p = Request["p"] } )that provides a formatting template to print some contents in a cell of a table. no problems, it works.
as this code could be more complex and reused in many places i was thinking to trasform it in a function to write just
format : MyFormattingTemplate("modify.cshtml", parameters : new { l = Request["l"], id = row["id"], lt = Page.Language, p = Request["p"] } )i can create MyFormattingTemplate to return a proper function and have the code working. i have only one problem:
that should be computed for every row. so, i searched a bit with no results, made same experiments... thought to encapsulate a lamba in an object this way
format : MyFormattingTemplate("modify.cshtml", parameters : new { l = Request["l"], id = new MyParameter((string columnName, DynamicRecord row) => row["id]), lt = Page.Language, p = Request["p"] } )and compute the parameter in MyFormattingTemplate calling a method of MyParameter.
is it good?!? can anyone give me a input?!?
hoping it is all clear, thanks
Amy Peng - M...
Star
11739 Points
1097 Posts
Microsoft
Re: [C# student] about transforming a lamba expression in a function
Jan 04, 2013 12:46 AM|LINK
Hi _pietro,
You can try to check the following how to use lamba expression:
http://msdn.microsoft.com/en-us/library/bb397687.aspx 。
http://www.codeproject.com/Articles/24255/Exploring-Lambda-Expression-in-C 。
http://www.codeproject.com/Articles/33323/Functional-Programming-in-C-3-0-using-Lambda-Expre 。
Best Regard,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store
_pietro
Member
17 Points
58 Posts
Re: [C# student] about transforming a lamba expression in a function
Jan 04, 2013 03:44 PM|LINK
thanks for the reply... i forgot to post i already solved my problem passing the lamba expression via anonymous type with something like this
var x = new { y = new Func<int,int,int> ((a,b) => a + b) };