Friday, September 04, 2009

Here's my generic collection question

[My Post]


I want to write code that is decouple and clean, and I know that by programming to an interface instead of the implementation, my code will be more flexible and extensible. So, instead of writing methods like:

bool IsProductAvailable(ProductTypeA product);

I write methods like:

bool IsProductAvailable(IProduct product);

As long as my products implement IProduct:

class ProductTypeA : IProduct


I should be OK. All is well until I start using generic collections. Since C# 3.0 doesn't support covariant and contravariant, even though both ProuctTypeA and ProductTypeB implements IProduct, you cannot put List in List. This is pretty troublesome because a lot of times I want to write something like:

bool AreProductsAvailable(List products);

So that I can check product avaialbility by writing:

List productsArrived = GetDataFromDataabase();
bool result = AreProductsAvailable(productsArrived);

And I want to write just one AreProductsAvailable() method that works with all IProduct collections.

I know that C# 4.0 is going to support covariant and contravariant, but I also realize that there other libraries that seemed to have the problem solved. For instance, I was trying out ILOG Gantt the gantt chart control, and found that they have a lot of collection intefaces that looks like this:

IActivityCollection
ILinkCollection

So it seems like their approach is wrapping the generic collection with an interface. So instead of "bool AreProductsAvailable(List products);", I can do:

bool AreProductsAvailable(IProductCollection products);

And then write some code so that IProductCollection takes whatever generic collection of IProduct, be it List or List.


However, I don't know how to write an IProductCollection interface that does that "magic". :-< (ashame) ....

Could someone shed me some light? This has been bugging me for so long, and I so wanted to do the "right thing". Well, thanks!

Thursday, September 03, 2009

JavaScript debugging with Visual Studio 2008: Awesome

I can't believe that I never tried debugging Javascript on Visual Studio 2008 before. I was relying on FireBug so far and it was not as integrate with my development workflow as I want. But with Visual Studio 2008, all I need is:

- Go to menu [File][Browse With...] and select "Internet Explorer" as your default debugging browser.
- In Internet Explorer, select menu [Tools][Internet Options...], then go to [Advanced] tab, under the "Browsing" group, make sure the item "Disable script debugging (Internet Explorer)" is NOT CHECKED.
- Set break point on the script in Visual Studio 2008.

That's it. Start debugging session and you will see you code stopped at the breakpoint you just set.

Friday, July 03, 2009

Somehow SQL CLR deployment doesn't work on office laptop but working on VM

I had problem getting SQL CLR development running in my desktop Visual Studio 2008 Test Edition. However it works on my VM. I really don't know what's the difference.
Well at least I find some way to continue working.

Journey to SQL CLR

Wednesday, May 06, 2009

Windows Server 2008 blue

Windows Server 2008 is so pain in the butt to deal with. Changing any minor stuff will require me to run the operation as administrator. Painful shit.

Monday, April 06, 2009

How to make your WPF automatically fill up the hosting form

I was puzzled about the fact that in WPF controls, there's nothing called Anchor. I was used to use Anchor to make the height and width to link to the size of the form with WinForm, but they are not there for WPF controls.

Finally I realized that the property of Height and Width for a WPF control can be set to "Auto". Doing so makes the control to automatically resize to match the form size. Pretty awesome.

Friday, March 20, 2009

slow slow VM

Totally feeling chocked by the slow slow VMWare. In addition, any USB access slows the machine down, like, dramatically.

So it's time to move on and not depending on the VM as much but instead rely more on environment on actual machine.

Now my life is relatively better.

Friday, March 06, 2009

Hmmm, View Model

So I was reading the MSDN article March 2009 issue about using Model View View-Model pattern. Then I tried to garb and run the sample project, but found that Visual Studio 2008 has problem opening the project. I turned out the I have to download the Microsoft® Silverlight™ Tools for Visual Studio 2008 SP1. I did and it works. It comes with the unit test framework for Siliverlight 2, so I don't have to download the Test Framework (Source Code and Unit Tests for Silverlight 2 Controls) saperately.

And to run the test, just following the instruction here.