Wednesday, April 28, 2010

This blog will be moving.

As I have posted earlier, this blog will be moving to a new address.

It should redirect automatically to the new address from May 1st, 2010.

Wednesday, March 31, 2010

Where C# fails, VB delivers.

Recently I've came across a strange behavior that took me some thinking to work around.

As you may know, my language of choice has been VB for as long as I can remember. However, I, like any good developer, can work just as good in C#. Really, it's no biggie.

Anyway, what I'm talking about here is dynamic type resolution.

For instance let's say we have the following VB program:

Module Program
  Sub Main()
    Dim value As Object = 123
    Format(123)
    Format(value)
  End Sub

  Sub Format(ByVal value As IFormattable)
    Console.WriteLine(value.ToString(Nothing, Nothing))
  End Sub
End Module

When ran, the above program will generate the following output:

123
123

Easy enough, huh?

Now, if we port this program to C# like this:

class Program
{
  static void Main(string[] args)
  {
    object value = 123;
    Format(123);
    Format(value);
  }
  static void Format(IFormattable value)
  {
    Console.WriteLine(value.ToString(null, null));
  }
}

Which is the literal translation of the VB program above, we can't even compile to program, because the C# compiler gives the following errors:

error CS1502: The best overloaded method match for 'DynamicCS.Formatter.Format(System.IFormattable)' has some invalid arguments

error CS1503: Argument '1': cannot convert from 'object' to 'System.IFormattable'

It's the same damn code, how come C# can't convert from object to IFormattable?

Well, the answer is that the C# compiler requires that all types to be known at compile time, rater than establish at runtime.

Sunday, March 14, 2010

Today is a sad day!

It's almost 11:30 pm, March 14th, 2010 when I've got an email from one of the many newsletters I subscribe.

The subject of the email was simply "Puppy", and that belies its true content, that for me was kind of a shock.

Joel is retiring from blogging.

I don't know if any of you know but I've began this site, this little corner in the Internet, because of Joel.

I've reading his columns, his posts, his insights on software development, business conduction, and many other subjects and little stuff he felt like sharing with the world.

And now, this is about to change.

I don't really know his reasons for doing this, although he did try to explain on his post. Whatever they might be, they are his own, and we must respect.

Anyway, I just wanted to vent it out of my chest.

Wednesday, March 03, 2010

VSTO Differences in VS2010 RC1

Yesterday I restarted working on an Oulook Add-in I'm cooking up for Office 2007 that I began developing in VS2010 Beta 2, and I got pissed when the code that was running quite well, simply gave me compiler errors.

Well apparently there were some changes from Beta 2 to RC 1 regarding the development of Office add-ins.

The main problem, for me, was that the class Microsoft.Office.Tools.CollectionBase<T> is gone so, any class that derives from it needed to be updated manually, and the affected classes were ThisFormRegionCollection and WindowFormRegionCollection that were changed from being a derived class of CollectionBase<Microsoft.Office.Tools.Outlook.IFormRegion> to be a derived class of Microsoft.Office.Tools.Outlook.FormRegionCollectionBase.

After changing this the code was recompiled successfully.

Building AsmMeta - follow up

A couple days ago I've written about the error I was getting when building an Windows Mobile control with design time capabilities. What I forgot to write about was the solution for the problem:

The problem occurred because in one of my classes was inheriting from a ReadOnlyCollection and this is not supported by the genasm.

As it's stated in this Microsoft Forum Thread.

So to work around this problem, I moved the classes that didn't require design time attributes to another assembly and the projects compiled just fine.

Thursday, February 25, 2010

Discoveries in Windows Mobile - Part 3

I've found in a russian site the meaning of all those colors I've posted about yesterday.

Here they are:

Color#Description
0 COLOR_ALERT
Obsolete.
1 COLOR_ACCENTTEXT
Obsolete.
2 COLOR_CALOFFHOURS
Obsolete.
3 COLOR_CALONHOURS
Obsolete.
4 COLOR_TODAYTEXT
Today screen text color.
5 COLOR_STARTICONBACKGROUND
Base color for title bar and soft keys
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
6 COLOR_TODAYSEPARATOR
Today screen separator line color.
7 COLOR_TODAYMENU
Today screen menubar background color.
8 COLOR_NAVBAR
Color of title bar
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
9 COLOR_NAVBARTEXT
Color of title bar text on
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
10 COLOR_NAVBARHILITE
Obsolete.
11 COLOR_NOTIFTRAY
Notification tray background color
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
12 COLOR_NOTIFTRAYHILITE
Background of highlighted icon in the notification tray
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
13 COLOR_BUBBLECAPTION
Left color of bubble caption background gradient on
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
14 COLOR_GRADIENTBUBBLECAPTION
Right color of bubble caption background gradient
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
15 COLOR_INTGRADLEFT
Left color of a gradient listview background, for the interlaced rows.
16 COLOR_INTGRADRIGHT
Right color of a gradient listview background, for the interlaced rows.
17 COLOR_HIGHGRADLEFT
Currently not used.
18 COLOR_HIGHGRADRIGHT
Currently not used.
19 COLOR_PHONEDIALERTEXT
Text color of the text in the Phone dialpad buttons.
20 COLOR_TRAYGRADLEFT
Base color for title bar and soft keys
Obs.:Windows Mobile 6 Standard only.
21 COLOR_TRAYGRADRIGHT
Right color of tray
Obs.:Windows Mobile 6 Standard only.
22 COLOR_TRAYTEXT
Tray text color
Obs.:Windows Mobile 6 Standard only.
23 COLOR_TRAYBKGND
Tray background color, if not a gradient
Obs.:Windows Mobile 6 Standard only.
24 COLOR_DIALPADBKGND
Currently not used.
25 COLOR_CRITGRADLEFT
Left color of a critical bubble caption gradient
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
26 COLOR_CRITGRADRIGHT
Right color of a critical bubble caption gradient
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
27 COLOR_BUBBLETITLE
Text color of a bubble caption
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
28 COLOR_CRITBUBBLETITLE
Text color of a critical bubble caption
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
29 COLOR_ALERTTITLE
Alert title text color. An alert is a full screen message box
Obs.:Windows Mobile 6 Standard only.
30 COLOR_ALERTWINDOW
Background color of a listview in alert. Also used for volume alert slider bar
Obs.:Windows Mobile 6 Standard only.
31 COLOR_ALERTRULE
Color of alert horizontal separator line. An alert is a full screen message box
Obs.:Windows Mobile 6 Standard only.
32 COLOR_HOMETEXT
Home Screen text
Obs.:Windows Mobile 6 Standard only.
33 COLOR_HOMERULE
Home Screen horizontal separator line
Obs.:Windows Mobile 6 Standard only.
34 COLOR_HOMEHIGHLIGHT
Home Screen background color of highlighted text
Obs.:Windows Mobile 6 Standard only.
35 COLOR_HOMEHIGHLIGHTTEXT
Home Screen highlighted text
Obs.:Windows Mobile 6 Standard only.
36 COLOR_GRADLEFT
Left color of a gradient listview background, used to draw alternating lines together with COLOR_INTGRADLEFT and COLOR_INTGRADRIGHT.
37 COLOR_GRADRIGHT
Right color of a gradient listview background, used to draw alternating lines together with COLOR_INTGRADLEFT and COLOR_INTGRADRIGHT.
38 COLOR_STARTMENU
Start Menu background color when there is no background bitmap
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.
39 COLOR_STARTMENUTEXT
Start Menu text.
40 COLOR_TAPANDHOLD
Tap and Hold
Obs.:Windows Mobile 6 Professional and Windows Mobile 6 Classic.