Errr, some catchy title.... RSS 2.0
 Friday, May 04, 2007

This is a quick post describing my first impressions with Silverlight 1.1 and Orcas Beta 1.

 

Orcas:

·        Overall: a step forward in a good direction. I really enjoy working with it. Can’t wait for Resharper to come out for it J.

·        I love that I can finally debug JavaScript.

·        Nice and clean separation: When you have Page.html, you also get Paga.html.js. Now, we have code behind for everythingJ.

·        XAML explorer is a lot faster when I compare it to VS 2005.

·        Running Silverlight application launches default browser in the system (in my case Opera). There is no plugin for Opera to make Silverlight working, so I always get the lovely image Get Silverlight. I had to set IE to be my default browser. In VS 2005 IE launched always no matter what was the default browser, I preferred it that way.

·        Ctrl + Right Arrow (and Ctrl + Left Arrow) don’t work! When I checked keyboard shortcuts in 2005 and Orcas they said exactly the same thing: Edit.MoveControlRight. Apparently this doesn’t work in Orcas on my machine. BTW: I had no idea how much I use this feature until it stopped working.

 

 

 

Silverlight:

  • Between 1.0 and 1.1 a HUGE step forward. I mean CLR on MAC, DLR and so on. My head still hurts….
  • It’s amazing I can write C# in my client app. I’ve written an Image Gallery for Silverlight 1.0 (actually when I wrote it, it was still WPF/E) and it wasn’t a joy ride. I didn’t enjoy debugging JavaScript with alert.
  • I’m rewriting it now to learn 1.1 and I’ve noticed that productivity boost is amazing. I truly believe that it will be possible to write simply amazing Rich Internet Applications with this technology.

 

 

Small Tip when building Silverlight applications with Orcas:

 

When you’re adding objects to XAML code that you want to reference in the code behind, make sure you use prefix x before Name property:

 

<Rectangle x:Name="mainPic" Width="448" Height="386" />

 

x of course corresponds to

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

Without that little x you will get compilation errors. It is a little bit counter intuitive since when you press n you also get a property Name, but this Name corresponds to the default schema

 

 

 

Friday, May 04, 2007 2:41:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Orcas | Silverlight
 Tuesday, January 23, 2007
Using Extension Methods with C# 3.0 and Orcas

I finally got around to play with January CTP release of Orcas (which is a codename for Visual Studio 2007). The first thing I wanted to try out are Extension Methods which are a new feature in C# 3.0 and VB 9.0 (and are included in .NET Framework 3.5).

 

Intro

 

So what are those Extension Methods?

 

In short: Extension Methods are static methods that are invoked with instance method syntax.

 

Why would I be interested in using them?

 

Well, they make your life easier. Isn’t that what it’s all about? J.

 

How to use it?

 

If you want to write a class that implements Extension Method, you must make it static. Furthermore the method must be static. Take a look at the code below:

 

public static class FirstExtension

   {

    public static int ToInt(this string target)

    {

    return Convert.ToInt32(target);

}

   }

 

 

Notice the keyword this in the method parameter. This indicates to the compiler (and IntelliSense) that this is an Extension Method. As you can see, the method takes in as a parameter a string and converts it into an integer. So one way of calling that method is:

 

string temp = "5";

int t = FirstExtension.ToInt(temp);

 

Nothing original here, but take a look at that:

 

string temp = "5";

int t = temp.ToInt();

               

 

So what exactly happened here? We created an instance of string object and we called a ToInt static method of class FirstExtension. So, as noted before this is nothing original, it just helps the developer to spend his time more productive.

 

 

There are a couple of things to consider:

  • Instance methods have always priority over Extension Methods.
  • It works with IntelliSense!
  • Checking for available Extension Methods is based on using / imports directive.
  • Currently, only Extension Methods are supported, properties, events and operators are currently being considered.

 

Usage

 

What I generally like about Extension Methods is the fact, that I’ll be able to write myself a Class Library, which will make my life easier. The first example provider is a great helper, because when you’re using DropDownLists and such, you always put the ID of the field in the Value and the Description in the Text.

Sooner or later you’ll have to convert the ID from string back to int. This extension will make the code more readable (and less writing for meJ).

 

Here are few other examples of the top of my head:

 

public static class CollectionHelper

    {

        public static void Consolize<T>(this IEnumerable<T> enumerable)

        {

            foreach(T ob in enumerable)

            {

                Console.WriteLine(ob.ToString());

            }

        }

    }

 

Usage:

 

Will iterate through whole collection and print out all objects to console.

string[] names = { "Burke", "Connor", "Frank",

"Everett", "Albert", "George",

"Harris", "David" };

 

names.Consolize();

 

Or another one:

 

public static class LogExt

{

public static void LogIt(this object ob)

{

Logger.Write(ob);

}

}

 

This will simply log all the data from the object (if you have overwritten ToString).

 

Note:

 

If you’re using Orcas January CTP and you copy pasted the code above you’ll get this exception:

 

Cannot use 'this' modifier on first parameter of method declaration without a reference to System.Core.dll. Add a reference to System.Core.dll or remove 'this' modifier from the method declaration

 

Simply add reference to System.Core.dll which is located in:

C:\WINDOWS\Microsoft.NET\Framework\v3.5.11209\System.Core.dll

Tuesday, January 23, 2007 1:15:38 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
C# 3.0 | Orcas
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Marcin Waligora
Sign In
All Content © 2008, Marcin Waligora
DasBlog theme 'Business' created by Christoph De Baene (delarou)