1. Extracting MVC HtmlHelper from HTML code
<td class = "Noborder NOPADDINGV" >
<div class = "AlignCenter" >
<a href= "/home/index" >
Src= ". /.. /resouces/images/agile/menu/campass48.png "alt =" Site Map "
title = "Sitemap" class = "ImageLink"/></a><br/>
Site Map
</div>
</td>
<td class = "Noborder NOPADDINGV" >
<div class = "AlignCenter" >
<a href= "/home/index" target = "_blank" >
Src= ". /.. /resouces/images/agile/help/help48.png "alt =" Help "title ="
Help "class =" ImageLink "/></a><br/>
Help
</div>
</td>
After the change:
@Html. Menuimagebuttonv ("Sitemap", False, "/home/index",
".. /.. /resouces/images/agile/menu/campass48.png ")
@Html. Menuimagebuttonv ("Help", "true", "/home/index",
".. /.. /resouces/images/agile/help/help48.png ")
This technique: When two pieces of code are the same, can become a function and two calls, the same part is the letter
Number, the different part is the invocation parameter.
2. The simplicity of the function interface:
Not writing a function is all right, bad function interface is still not concise. Here is a newly-changed
Example:
@Html. ImageLink ("Burn Chart", True,
".. /.. /resouces/images/agile/currentsprint/burndowndata16.png "," Icons ",
False, "/agile/currentsprint/burndowndata", NULL, NULL)
@Html. ImageLink ("Iteration plan", True,
".. /.. /resouces/images/agile/sprints/index16.png "," Icons ", False,
"/agile/sprints/index", NULL, NULL)
...
Modified result (another piece of code):
@Html. ImageLink ("Iteration plan", "/agile/sprints/index", true)//This true some
The place was not quite the same so it stayed.
@Html. ImageLink ("Iteration Story", "/agile/sprints/sprintstories", True)
This technique: If some parameters change when the function is called repeatedly, some parameters are basically the same ("Icons",
True, False, null .... ), which should turn into optional parameters and set default values.
Beginner C # code Simplicity-function Chapter