Now I would like to use this method with an input that is not an array of doubles, but some other list of double values (say List<double>, a RowCollection, whatever).

The straight-forward solution is to change the Sum method to receive a collection instead of an array, or make it a template method. But that's when I can change it! What if the method belongs to some class that is not under my jurisdiction?

In this case, the only solution I can think of is to create a whole new array of doubles based on the collection you want to work with. But of course, that's not what I want! First, it costs time and memory. Second, if the Sum method would also change the actual values in the array - you're lost. In my case, it's the first restriction that bugs me.

If the input variable was something else than an array (some class), in most cases you would be able to solve it by inheriting from it and feeding the child class to the method. But then again it wouldn't work for all cases. First because the lack of multiple inheritance (sigh) could restrain you from such solution. Second, in the case the input variable is of some sealed type.

My solution (proposal) - impersonation.

A possible implementation would be an attribute on the class that indicates to the compiler that an object of this type could be used to substitute some other type. For example:

[Impersonate(typeof(double[]))]publicclassMyCollection{// Implement the parts of double[] you are going to need}

Note that in theory, one could implement in MyCollection only those parts of Array that might indeed be called. Then the call to the method could be done as so:

And, of course, the compiler should be able to understand the attribute and not generate any errors. Unless, of course, the Sum method uses some features of Array that are not implemented in MyCollection .

Sunday, September 16, 2007

Today I wanted to define one accessor with two different accessibility levels. That is, I wanted a property to have public 'get' access and private 'set' access. I remembered that in .NET 2.0 this became possible, but didn't remember exactly the syntax. So I tried first my intuition, which was:

publicDataTable MyTable{get { return myTable; }}

privateDataTable MyTable{set { myTable = value; }}

Unfortunately, I was wrong. A quick search revealed the secret syntax:

Today, my friends, I admit I had no idea what I was talking about, because until that moment I didn't run into any problem with the machine. Now that I have, and had to get (no) help from their laptops lab I must say the exact contrary - DO NOT buy LG laptops in Israel, if you want your warranty to have any meaning!

Huh? What? What happened???

I'll try to make it short:

1. It's been some time now that I had 2 main issues with the laptop:

a. It would suddenly freeze, leaving me no alternative but to hard-reboot it.

b. The mouse buttons didn't work well.

2. At some point I couldn't work with it anymore, so I had to bring it to the lab. The machine is 2 years old, the warranty is for 3 years - should be a no-brainer.

3. Since the lab is at a remote location, I brought it to a computer shop/lab that works with LG and provide a service of sending/receiving stuff to/from the lab. So far so good.

4. After almost 3 weeks, the laptop was back.

a. They fixed the mouse-buttons.

b. The freezing was answered by the so-annoying "you must reinstall Windows".

c. When I got home I realized that the battery didn't work anymore!!! When I sent it to the lab, the battery was still able to provide me with ~2 hours of work. Now I got it back completely broken: 0 juice, 0 recharge!!!

5. I sent it back to the lab, got it back after again almost 3 weeks, with the even more frustrating answer that the warranty is not valid for batteries. I talked to the lab director, but bumped into a solid wall.

6. Last night I reinstalled Windows. Guess what - when I worked with it now it got frozen once again...