Category Archives: Orcas

VS 2008 JavaScript Intellisense

Taken from Scott Guthrie’s blog, this article show us one of the most wanted new features – JavaScript Intellisense:

One of the features that web developers will really like with VS 2008 is its built-in support for JavaScript intellisense. This is enabled in both the free Visual Web Developer 2008 Express edition as well as in Visual Studio, and makes using JavaScript and building AJAX applications significantly easier.

Below is a quick tour of some of the new JavaScript intellisense features to take advantage of:


JavaScript Type Inference

One of the things you’ll notice immediately when you start typing within a script block is the richer support that Visual Studio 2008 now has for JavaScript keywords and language features:

step1 VS 2008 JavaScript Intellisense

JavaScript is a dynamic language, and doesn’t support explicit type declarations, which has made implementing good intellisense difficult in the past.

Visual Studio 2008 adds support for type inference, which means that it evaluates and computes how a JavaScript block is being used and dynamically infers the variable usage and type information of the code to provide accurate intellisense support.

For example, Visual Studio below will infer that an html element is being retrieved by the document.getElementById() method, and provide appropriate html element intellisense for the variable result:

step2 VS 2008 JavaScript Intellisense

read all

VS 2008 Multi-Targeting Support

Thats valuable, Scott Guthrie is describing how the multi-targeting works into new named VS 2008. The idea is to have the new IDE working with 2.0 framework. Unfortunately 1.1 isnt supported. Here is his post:

Earlier this month at TechEd we announced the official name of Visual Studio “Orcas” – which will be called Visual Studio 2008. We also said that the official name for the .NET Framework “Orcas” release will be called .NET Framework 3.5 (it includes the new LINQ support, integrated ASP.NET AJAX support, new ASP.NET data controls, and more).

VS 2008 and .NET 3.5 Beta 2 will ship later this summer, and the Beta 2 release will support a go-live license for those who want to put applications into production using the new features immediately.
What is Multi-Targeting?

With the past few releases of Visual Studio, each Visual Studio release only supported a specific version of the .NET Framework. For example, VS 2002 only worked with .NET 1.0, VS 2003 only worked with .NET 1.1, and VS 2005 only worked with .NET 2.0.

One of the big changes we are making starting with the VS 2008 release is to support what we call “Multi-Targeting” – which means that Visual Studio will now support targeting multiple versions of the .NET Framework, and developers will be able to start taking advantage of the new features Visual Studio provides without having to always upgrade their existing projects and deployed applications to use a new version of the .NET Framework library.

Now when you open an existing project or create a new one with VS 2008, you can pick which version of the .NET Framework to work with – and the IDE will update its compilers and feature-set to match this. Among other things, this means that features, controls, projects, item-templates, and assembly references that don’t work with that version of the framework will be hidden, and when you build your application you’ll be able to take the compiled output and copy it onto a machine that only has an older version of the .NET Framework installed, and you’ll know that the application will work.

So why use VS 2008 if you aren’t using the new .NET 3.5 features?

You might be wondering: “so what value do I get when using VS 2008 to work on a ASP.NET 2.0 project versus just using my VS 2005 today?” Well, the good news is that you get a ton of tool-specific value with VS 2008 that you’ll be able to take advantage of immediately with your existing projects without having to upgrade your framework/ASP.NET version. A few big tool features in the web development space I think you’ll really like include:

1. JavaScript intellisense
2. Much richer JavaScript debugging
3. Nested ASP.NET master page support at design-time
4. Rich CSS editing and layout support within the WYSIWYG designer
5. Split-view designer support for having both source and design views open on a page at the same time
6. A much faster ASP.NET page designer – with dramatic perf improvements in view-switches between source/design mode
7. Automated .SQL script generation and hosting deployment support for databases on remote servers

You’ll be able to use all of the above features with any version of the .NET Framework – without having to upgrade your project to necessarily target newer framework versions. I’ll be blogging about these features (as well as the great new framework features) over the next few weeks.

What about .NET 1.0 and 1.1?

Unfortunately the VS 2008 multi-targeting support only works with .NET 2.0, .NET 3.0 and .NET 3.5 – and not against older versions of the framework. The reason for this is that there were significant CLR engine changes between .NET 1.x and 2.x that make debugging very difficult to support. In the end the costing of the work to support that was so large and impacted so many parts of Visual Studio that we weren’t able to add 1.1 support in this release.

VS 2008 does run side-by-side, though, with VS 2005, VS 2003, and VS 2002. So it is definitely possible to continue targeting .NET 1.1 projects using VS 2003 on the same machine as VS 2008.

What is compatibility like moving from VS 2005 to VS 2008 and .NET Framework 2.0 to 3.5?

We are trying to make sure that .NET Framework 3.5 is a super compatible upgrade from .NET 2.0, and not require you to change any code in order to target the new framework version. We’ve deliberately made only non-breaking modifications to existing .NET assemblies in the .NET 3.5 release, and where possible added new features in separate assemblies to minimize the chance of breaking changes.

We are also not making project model or build changes with VS 2008. I, like you, hope to never to go through that again! Both the “web site” and “web application project” models will be fully supported going forward.
read original

Orcas 1 Partial Methods

Partial Methods

One feature that you may have not heard of yet is a feature called partial methods. This is some of the work that I did in the last coding milestone a few months back. Partial methods are methods that enable lightweight event handling. Here is an example declaration:

partial class C
{
static partial void M(int i);
}

There are a few notable things here:

1. Partial methods must be declared within partial classes

2. Partial methods are indicated by the partial modifier

3. Partial methods do not always have a body (well look at this more below)

4. Partial methods must return void

5. Partial methods can be static

6. Partial methods can have arguments (including this, ref, and params modifiers)

Now suppose that I make a call to C.M.

partial class C
{

static void Main()
{
C.M(Calculation());
}
}

Since M has no body, all calls to C.M are removed at compile time as well as the evaluation of the arguments. So the above program is equivalent to:

partial class C
{

static void Main()
{
}
}

In this sense, partial methods are the distant cousins of conditional methods which also sometimes remove the call and the evaluation of the arguments. But partial methods go even further. When a partial method has no body then the partial method is not even emitted to metadata.

So far this might seem a little confusing. C# now allows users to declare methods for which the calls, the evaluation of the arguments, and the method itself are not emitted. Fortunately, the story doesn’t end there. Partial methods allow users to define a body for the method so that the method, the calls, and the evaluation of the arguments are emitted.

partial class C
{
static partial void M(int i); // defining declaration
static partial void M(int i) // implementing declaration
{
}
}

In the code above, we see that there is a difference between a defining declaration of a partial method and an implementing declaration of a partial method and the difference is whether or not the method has a body. These definitions don’t have to be in the same partial class declaration. There may only be one defining declaration and if a defining declaration exists then there may be an implementing declaration.

Why Partial Methods?

So how are these partial methods used? The common scenario is to use them to do lightweight event handling. For example a tool that generates code may wish to have hooks for users to customize what code is run. For example, imagine that a tool generated a bunch of code for a class representing a customer. It might look like this:

partial class Customer
{
string name;

public string Name
{
get
{
return name;
}
set
{
OnBeforeUpdateName();
OnUpdateName();
name = value;
OnAfterUpdateName();
}
}

partial void OnBeforeUpdateName();
partial void OnAfterUpdateName();
partial void OnUpdateName();
}

If the user doesn’t add any implementing definitions then this code is equivalent to:

partial class Customer
{
string name;

public string Name
{
get
{
return name;
}
set
{
name = value;
}
}

}

No extra metadata for things that are not used and no extra instructions for useless operations. On the other hand if the user listened to the OnUpdateName “event” like this:

partial class Customer
{
partial void OnUpdateName()
{
DoSomething();
}
}

Then the original definition is equivalent to:

partial class Customer
{
string name;

public string Name
{
get
{
return name;
}
set
{
OnUpdateName();
name = value;
}
}

partial void OnUpdateName();
}

Comparing Partial Methods to the Alternatives

At this point, it is sensible to ask why not just use subclassing and virtual methods? Of course, this would also work but it does have the drawback that the calls, the methods, and the evaluation of the arguments will still be emitted even if the virtual methods are not overridden. So in a system like Linq to SQL that has thousands of little events it allows these events to be very lightweight so that the user only pays for those events that she uses.

A Few Fine Points

Consider the following program…

partial class C
{
static void Main()
{
int i = 3;
C.M(i = 5);
Console.WriteLine(i);
}
}

What does it write to the console? 3, 5, …?

Actually, it is impossible to tell from just this code. If there is no implementing declaration then the program will display 3 because the i = 5 will never be evaluated, but if there is an implementing declaration then the program will display 5. The same is true for conditional methods. So if you want a side-effect to occur make sure you do not cause the side-effect to occur as an argument to a partial method. Of course, the same trick can be used to hide expensive calculations.

partial class C
{
static void Main()
{
C.M(VeryVeryExpensiveCalculation());
}
}

If there is no implementing declaration then the very very expensive calculation will never be performed.

Now what about attributes, how does those work?

partial class D
{
[W]
[return:X]
partial void M([Z]int foo)
{
}

[Z]
[return:W]
partial void M([Y]int foo);
}

What attributes are actually emitted on M? W and Z are the attributes on M; X and W are the attributes on the return type; Y and X are the attributes on the type parameter; Z and Y are the attributes on the parameter.

read original

Full screen experience with Silverlight

Mr.Guthrie is presenting how Silverlight uses entire browser window:

One of the nice features that Silverlight supports is the ability to go “full screen” and effectively take over the entire screen of a computer (hiding everything else from sight – including the browser frame). This can be very useful when building immersive UI experiences, games, rich video players, etc.

For a nice example of this feature in action, make sure to check out the Fox Movies Sample on www.silverlight.net:

step1 Full screen experience with Silverlight

Once the page loads and the movie starts playing, double-click on the video surface in the middle to switch into full-screen mode (note: the screen-shot above is not in full-screen but rather browser mode). You can then hit the escape key to switch back into normal browser viewing.

How to Implement Full Screen Mode with Silverlight 1.1 using .NET

One of the questions I’ve seen a few people ask is “how can you implement full screen-mode when building Silverlight applications using .NET?” The good news is that the answer is actually pretty easy:

1) First add an input driven event handler to your application (for example: a mouse down or keyboard event handler). For security reasons Silverlight doesn’t allow developers to switch an application into full-screen mode on first application load (you don’t want an application to spoof you). So you’ll instead need to trigger full-screen mode in response to a user action.

2) Within your input event handler set the BrowserHost.IsFullScreen property to true (note: the BrowserHost class lives within the System.Windows.Interop namespace). This will cause Silverlight to switch into full screen mode. Setting this property to false will return it back to normal browser mode.

Simple Full Screen Mode Sample

You can download a simple Silverlight full screen-mode sample I put together written in C# here.

When you run the sample it will load a super simple Silverlight application within the browser and display a text message prompting you to click it to switch into full-screen mode:

step3 Full screen experience with Silverlight

If you click the “Click for Full Screen” text, the application will switch into full-screen mode – which will hide everything else running on the system and take over the entire screen:

step4 Full screen experience with Silverlight

When you switch into full-screen mode, Silverlight will display a user message blurb that will pop-up on the screen for a few seconds and instruct the user that they can press the escape key to switch back into browser mode. After a few seconds this message will disappear and only your content will be visible. In my sample above I also allow the user to click on the “Click to Return to Browser” text and switch back into browser mode as well.

Walkthrough the Simple Full Screen Mode Code

The code to implement the above sample is pretty simple.

To begin with we can open and edit the root .XAML file for the application, and add a UI element to it that we want to use to trigger the full-screen mode. In the sample above I used a control that I named “MyMessage”. Below is all of the XAML for the entire application:

step2 Full screen experience with Silverlight

The below screen-shot shows the code-behind for the .XAML file above – and contains all of the code for the entire application:

step5 Full screen experience with Silverlight=”">

Within the application’s Page_Loaded() event handler above I am wiring up two event handlers:

MyMessage_MouseLeftButtonDown – This event handler will execute anytime a user clicks on the TextBlock message control I added into my XAML file. Within this event handler I’m simply toggling the BrowserHost.IsFullScreen property to true or false depending on whether or not it is already in full screen mode.

BrowserHost_FullScreenChange – This event handler will execute anytime Silverlight switches between full screen and browser mode. It provides a good place to add logic to update the UI when this happens. In the example above I am changing the text on the TextBlock control. I could also have optionally resized controls and/or moved them around the screen to new coordinate positions. Currently the Silverlight 1.1 Alpha doesn’t have layout manager support, so controls won’t automatically re-position unless you write code to manage this yourself (don’t worry – layout manager controls for Silverlight like in the desktop WPF version are coming).

In addition to the IsFullScreen property, BrowserHost class has a number of additional properties and events that are very useful:

step6 Full screen experience with Silverlight

The ActualHeight and ActualWidth properties are particularly useful to lookup the screen dimensions when you switch into full-screen mode – which you can then use when positioning and scaling your UI controls on the page.

Summary

Supporting full-screen mode within Silverlight applications is pretty easy to enable, and offers the ability to provide a nice, immersive user experience.

To learn more about Silverlight, please read my comprehensive Silverlight announcement post as well as visit the www.silverlight.net community site.

To watch me walkthrough building a Silverlight application from scratch using .NET and Visual Studio “Orcas”, please watch this video here.


view original

Anonymous Types in Orcas

Scott is providing us with series of lessons about newly developed Orcas features. This time its time for Anonymous Types. Let see what his post is about:

What are Anonymous Types?

Anonymous types are a convenient language feature of C# and VB that enable developers to concisely define inline CLR types within code, without having to explicitly define a formal class declaration of the type.

Anonymous types are particularly useful when querying and transforming/projecting/shaping data with LINQ.

Anonymous Type Example

In my previous Query Syntax blog post I demonstrated how you could transform data with projections. This is a powerful feature of LINQ that enables you to perform query operations on a data source (regardless of whether it is a database, an XML file, or an in-memory collection), and shape the results of the data being queried into a different structure/format than the original data source is in.

In my previous Query Syntax blog post I defined a custom “MyProduct” class that I used to represent my transformed product data. By explicitly defining the “MyProduct” class I have a formal CLR type contract that I can use to easily pass my custom-shaped product results between web-services or between multiple classes/assemblies within my application solution.

However, there are times when I just want to query and work with data within my current code scope, and I don’t want to have to formally define an explicit class that represents my data in order to work with it. This is where anonymous types are very useful, as they allow you to concisely define a new type to use inline within your code.

For example, assume I use the LINQ to SQL object relational mapper designer within “Orcas” to model the “Northwind” database with classes like below:

step1 Anonymous Types in Orcas

I can then use the below code to query the Product data in my database, and use the projection/transformation capability of LINQ to custom shape the data result to be something other than the “Product” class above. Rather than use an explicitly defined “MyProduct” class to represent each custom-shaped row of data retrieved from the database, I can instead use the anonymous type feature to implicitly define a new type with 4 properties to represent my custom shaped data like so:

step5 Anonymous Types in Orcas

In the code above I’m declaring an anonymous type as part of the select clause within my LINQ expression, and am having the compiler automatically create the anonymous type with 4 properties (Id, Name, UnitPrice and TotalRevenue) – whose property names and type values are inferred from the shape of the query.

I’m then using the new “var” keyword within C# to programmatically refer to the IEnumerable sequence of this anonymous type that is returned from the LINQ expression, as well as to refer to each of the anonymous type instances within this sequence when I programmatically loop over them within a foreach statement later in my code.

While this syntax gives me dynamic language-like flexibility, I also still retain the benefits of a strongly-typed language – including support for compile-time checking and code intellisense within Visual Studio. For example, notice above how I am doing a foreach over the returned products sequence and I am still able to get full code intellisense and compilation checking on the anonymous type with custom properties that was inferred from the LINQ query.

Understanding the Var Keyword

C# “Orcas” introduces a new var keyword that may be used in place of the type name when performing local variable declarations.

A common misperception that people often have when first seeing the new var keyword is to think that it is a late-bound or un-typed variable reference (for example: a reference of type Object or a late-bound object like in Javascript). This is incorrect — the var keyword always generates a strongly typed variable reference. Rather than require the developer to explicitly define the variable type, though, the var keyword instead tells the compiler to infer the type of the variable from the expression used to initialize the variable when it is first declared.

The var keyword can be used to reference any type in C# (meaning it can be used with both anonymous types and explictly declared types). In fact, the easiest way to understand the var keyword is to look at a few examples of it using common explict types. For example, I could use the var keyword like below to declare three variables:

step6 Anonymous Types in Orcas

The compiler will infer the type of the “name”, “age” and “male” variables based on the type of their initial assignment value (in this case a string, an integer, and a boolean). This means it will generate IL that is absolutely identical to the code below:

step7 Anonymous Types in Orcas

The CLR actually never knows that the var keyword is being used – from its perspective there is absolutely no difference between the above two code examples. The first version is simply syntactic sugar provided by the compiler that saves the developer some keystrokes, and has the compiler do the work of inferring and declaring the type name.

In addition to using built-in datatypes with the var keyword, you can obviously also use any custom types you define. For example, I could go back to the LINQ query projection I did in my previous blog post that used an explicit “MyProduct” type for the data-shaping and adapt it to use the var keyword like so:

step8 Anonymous Types in Orcas

Important: Although I’m using the “var” keyword above, I’m not using it with an anonymous type. My LINQ query is still shaping the returned data using the “MyProduct” type – which means that the “var products” declaration is simply a shorthand for “IEnumerable products”. Likewise, the “var p” variable I defined within my foreach statement is simply shorthand for a a variable of type “MyProduct p”.

Important Rule about the Var Keyword

Because the var keyword produces a strongly-typed variable declaration, the compiler needs to be able to infer the type to declare based on its usage. This means that you need to always do an initial value assignment when declaring one. The compiler will produce a compiler error if you don’t:

step9 Anonymous Types in Orcas

Declaring Anonymous Types

Now that we’ve introduced the “var” keyword, we can start to use it to refer to anonymous types.

Anonymous types in C# are defined using the same object initializer syntax I covered in my first blog post in this language series. The difference is that instead of declaring the type-name as part of the initialization grammar, when instantiating anonymous types you instead just leave the type-name blank after the “new” keyword:

step10 Anonymous Types in Orcas

The compiler will parse the above syntax and automatically define a new standard CLR type that has 4 properties. The types of each of the 4 properties are determined based on the type of the initialization values being assigned to them (for example: in the sample above the “Id” property is being assigned an integer – so the compiler will generate the property to be of type integer).

The actual CLR name of the anonymous type will automatically be generated by the C# compiler. The CLR itself actually doesn’t know the difference between an anonymous type and a named type – so the runtime semantics of the two are absolutely identical. Bart De Smet has a good blog post here that details this if you want to see the exact class name pattern and IL generated.

Note above how when you type “product.” on the anonymous type, you still get compile-time checking and full intellisense within Visual Studio. Notice also how the intellisense description indicates it is an “AnonymousType” – but still provides full declaration information of the properties (this is the text circled in red).

Using Anonymous Types for Hierarchical Shaping

One of the powerful scenarios that anonymous types makes easy is the ability to easily perform hierarchical shape projections of data with a minimum amount of code.

For example, I could write the below LINQ expression to query all products from the Northwind database whose price is greater than $50, and then shape the returned products in a hierarchical structure sorted by the Products’ stock reorder level (using the “group into” clause supported by LINQ query syntax):

step11 Anonymous Types in Orcas

When the above code is run in ASP.NET, I’ll get the below output rendered in my browser:

step12 Anonymous Types in Orcas

I could likewise do nice hierarchical shapings based on JOIN results. For example, the below code creates a new anonymous type with some standard product column properties, as well as a hierarchical sub-collection property that contains the orderdetails of the 5 most recent orders that customers have placed for that particular product:

step13 Anonymous Types in Orcas

Notice how I can neatly traverse the hierarchical data. Above I’m looping over the product query, and then drilling into the collection of the last 5 orders for each product. As you can see, I have full intellisense and compile-time checking everywhere (even on properties of objects within the nested sub-collection of order details on the anonymous type).

Data Binding Anonymous Types

As I mentioned earlier in this blog post, there is absolutely no difference from a CLR perspective between an anonymous type and an explicitly defined/named type. Anonymous types and the var keyword are purely “syntactic sugar” that avoid you having to type code – the runtime semantics are the same as using explicitly defined types.

Among other things, this means that all of the standard .NET type reflection features work with anonymous types – which means that features like databinding to UI controls work just fine with them. For example, if I wanted to display the results of my previous hierarchical LINQ query, I could define an control within a .aspx page like below:

step14 Anonymous Types in Orcas

The .aspx above contains a gridview with 2 standard boundfield columns, and one templated field column that contains a nested control that I’ll use to display the product’s hierarchical orderdetail sub-results.

I could then write the below LINQ code to perform my hierarchical query against the database and databind the custom-shaped results against the GridView to display:

step14.5 Anonymous Types in Orcas

Because the GridView supports binding against any IEnumerable sequence, and uses reflection to retrieve property values, it will work just fine against the anonymous type I’m using above.

At runtime the above code will produce a simple grid of product details with a hierarchical list of their recent order quantities like so:

step15 Anonymous Types in Orcas

Obviously you could make this report much richer and prettier – but hopefully you get the idea of how easy it is to now perform hierarchical queries against a database, shape the returned results however you want, and then either work against the results programmatically or databind them to UI controls.


Summary

Anonymous types are a convenient language feature that enable developers to concisely define inline CLR types within code, without having to explicitly provide a formal class declaration of the type. Although they can be used in lots of scenarios, there are particularly useful when querying and transforming/shaping data with LINQ.

This post concludes my 5-part language series for “Orcas”. Going forward I’ll be doing many more LINQ posts that will demonstrate how to actually take advantage of all of these new language features to perform common data access operations (defining data models, querying, updating, using sprocs, validation, etc). I wanted to get this 5 part language series done first, though, so that you’ll have a good way to really understand the underlying language constructs as we drill into scenarios within my upcoming posts.

view original

Javascript Intellisense in Visual Studio "Orcas"

Scott Guthrie is writting about new JavaScript Intellisense here:
 Javascript Intellisense in Visual Studio "Orcas"
“If you have ever been frustrated by manually typing Javascript before, you are going to be in for a pleasant treat with “Orcas”. Visual Studio now provides full Javascript Intellisense completion in .aspx files, .htm files, as well as in external .js files. It delivers Intellisense for vanilla Javascript code, as well as provides rich support for the new ASP.NET AJAX client Javascript framework and Javascript code built with it.”
view original

My First Orcas Beta1 Review

vwd on My First Orcas Beta1 Review
Last night I had the chance(meaning time) to download and install the new Beta1 release. Here will share some of my first impressions. Actually I played with WebDeveloper Express version and that one left me with very nice impression.

After clean install on my quite old PC seems very light and not memory consuming. I started new ASP.NET project and wrote some lines. What is obvious is that in the control toolbox on the left you can find all old set of controls as weel as some new ones like AJAX controls. Havent chance to play and investigate much but I have noticed nice and new XML controls.

That Express edition comes with lightweight web server which runs aside IIS, so you dont need to upgrade it or make any configuration there.

While writting code new intellisense made me nice impression as well as the ability to omit function parameters which arent used in the function body.

Stay tooned for more after the weekend.

Here is a link to updated Visual Studio Orcas Samples
Here is a link to Visual Web Developer Orcas Express Edition

First look at Orcas Beta1

aa700831.1VS1 First look at Orcas Beta1
Yes, its here! Well currently not final but it will show you the way. Many new features are planed to ship with the final release. So far some of the new features are:

– Intellisense Everywhere
– Relaxed Delegates
– Multi-Targeting

Here is the download page
Here is the link to a group blog from members of the VB team

New "Orcas" Language Feature: Lambda Expressions

Scott Guthrie is as usually explaining the new features of the new Orcas Studio. This time he looks over the Lambda Expressions. Up to now they arent supported in VB but only in C#. Looking forward to see them in VB!

So here is what Scott wrote:
step1 New "Orcas" Language Feature: Lambda Expressions

What are Lambda Expressions?

C# 2.0 (which shipped with VS 2005) introduced the concept of anonymous methods, which allow code blocks to be written “in-line” where delegate values are expected.

Lambda Expressions provide a more concise, functional syntax for writing anonymous methods. They end up being super useful when writing LINQ query expressions – since they provide a very compact and type-safe way to write functions that can be passed as arguments for subsequent evaluation.
view original

New Data Tools Features in Visual Studio Orcas

On the Visual Basic Team blog there is interesting post about “New Data Tools Features in Visual Studio Orcas” following are four major ones:

  1. Object Relational Designer
  2. Hierarchical Update in Typed Dataset
  3. N –Tier Support in Typed Dataset
  4. Local Data Cache with SQL Compact Edition

view original