Related articles: teach you 30 seconds to build strong type ASP.net data binding, strongly typed ASP.net data binding improved version 2nd
Read Dragonpig wrote "teach you 30 seconds to build strong type ASP.net data binding," a bright, is really too much power, the original can also be data binding.
Immediately a small try, and made some improvements, has now been applied to the news column in the home. Let's share some of the improvements.
With the traditional asp.net data-binding approach, there are two places that have been uncomfortable:
1 lack of intelligent perception;
2 Force type conversion.
Let's take a look at the traditional ASP.net data binding:
Look at the above ToString (), (DateTime) ...
Dragonpig's strongly typed binding mentality already contains a way to solve both of these problems, but in the code he shows, the first problem (IntelliSense) is ignored, but the second problem (coercion type conversion) is omitted, and the original code is as follows:
Protected virtual Object exphelper<tentity, tresult> (func<tentity, tresult> Func)
{
var itm = Getdataitem ();
return func ((tentity) ITM);
}
Protected Object Stu<tresult> (Func<student, tresult> Func)
{
Return exphelper<student, Tresult> (func);
}
I found in the use of forced type conversion, a bit uncomfortable, research, the original is the trouble of object, as long as the above code two object to TResult, the problem is solved.
In addition, I changed the Stu method name to Eval, which feels more friendly.
Code on:
Protected virtual TREsult exphelper<tentity, tresult> (func<tentity, tresult> Func)
{
var item = base. Getdataitem ();
return func ((tentity) item);
}
Protected TResult eval<tresult> (Func<newsinfo, tresult> Func)
{
Return Exphelper<newsinfo, Tresult> (func);
}
The days after strong type asp.net data binding are wonderful ...
Thank dragonpig! Your sharing is too good!