Tuesday, February 10, 2009

Extension method

Extension method is a new feature available in .NET 3.0 framework. Extension Method enable a variety of useful scenarios, and help make possible the really powerful LINQ query framework that is being introduced with .NET as part of the VS 2008 / .NET 3.5 release. The usage is shown in the below snapshot.



Beware to simply insert the this keyword before the int argument in the Double() helper method, which make the extension method possible, then we can indeed type side.Double(). In fact, the advantage of doing this is that intellisense will help you by showing the method in the dropdown when you type a dot after the variable and also makes something more readable. The extension method should be static and class as well.
However extension method should be avoided in cases where encapsulation breaks.

Monday, February 9, 2009

Inheritance in WPF

Completely new to Windows Presentation Foundation (WPF). It was quite interesting to learn it. During coding I was happened to use inheritance. As usual in any ‘C’ coding style programming language I followed the pattern BaseClass : DerivedClass in my .xaml pages. I was getting build error until I discover the additional add-on code. The code snippet is shown below.


Instead of the Window or UserControl tag, we need to use Src tag followed by the file name (here PageBase, for my PageBase.cs file). To make that file to be recognized we need to specify the namespace too, which is done in xmlns:src property. This piece makes inheritance to happen.

Thursday, February 5, 2009

Manage Control Visibility Using CSS in Server Side

There are some situations we make our controls visibility to false in our page load and try to access that very same control in JavaScript. Since its visibility is set false, that control wont be rendered in the HTML and the poor JavaScript could not find that element.
Instead of using ‘Visible’ property we can use CSS to get that work done. It will make the control invisible and at the same time, using JavaScript, we can able to find that control as well. Code snippet shown below.