CodersBarn.com
The ASP.NET Community Blog

Covariance, Contravariance and Invariance in C# 4.0

June 7, 2009 11:23 by agrace

C# 4.0 is the next version of the C# language being shipped with VS 2010. Personally, I'm still coming to terms with Generics as introduced in C# 2.0 and LINQ which came with 3.0. Anders Hejlsberg touched on the Covariance/Contravariance topic in his TechEd presentation in LA last month entitled "The Future of C#".

Evolution of C# - Anders Hejlsberg

The terms Invariance, Covariance and Contravariance are not by any means new. Anyone coming from a computer science background will have encountered the terms. Prior to attending Anders' session, I hadn't given this much conscious thought in a long time - we tend to know what we can and can't do within the syntactical constraints of a language - and tend not to question things further. However, in C# 4.0, delegates and interfaces will play nicer when working with generics. So much attention is likely to be focused on the dynamic programming additions in C# 4.0 (mainly in support of LINQ), that this addition may go unnoticed.

Variance in C# 4.0 - Anders Hejlsberg - Anders Hejlsberg

Terminology:

Invariant: A return parameter is invariant if we must use the exact match of the type name. In other words, neither covariance nor contravariance is permitted

Covariant: A parameter is covariant if we can use a more derived type as a substitute for the parameter type. In other words, a subclass instance can be used where a parent class instance was expected.

Contravariant: A return value is contravariant if we can assign the return type to a variable of a less derived type than the parameter. In other words, a super class instance can be used where a subclass instance was expected.

Variance in C# 4.0 - Anders Hejlsberg - Anders Hejlsberg

Generally, C# supports covariant parameters and contravariant return types. There has always been support for covariance and contravariance in C# - C# 4.0 will just ensure that generic delegates and interfaces will also behave they way we would expect.

Eric Lippert is the developer responsible for this feature of the C# 4.0 release and has an eleven-part blog series on just this topic. I would also recommend reading Charlie Calvert's article on this topic for some code samples.

Side Note: You do not need VS 2010 to experiment with these features - just download the framework to a test VM.

kick it on DotNetKicks.com   vote it on Web Development Community


Tags: , ,
Categories: .NET 4.0 | C#
Actions: E-mail | Permalink | Comments (14) | Comment RSSRSS comment feed

Set Color of GridLines in Gridview

May 31, 2009 07:04 by agrace

There are times when you will want to set the color of the grid lines in your GridView - however there is not to my knowledge a way of doing this declaratively. A workaround is to do this by tapping into the GridView's RowDataBound event.

GridView Gridlines

First, set the OnRowDataBound property in the markup of the GridView:

OnRowDataBound="MyGrid_RowDataBound"


Second, set the color in the OnRowDataBound handler method:

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
     foreach (TableCell tc in e.Row.Cells)
     {
         tc.Attributes["style"] = "border-color: #c3cecc";
     }
}


Happy coding :-)

Update 06-01-2009:
See Lee's suggestion in the comments on a quicker way to do this:
Add this to the page Load method: this.GridView1.Attributes.Add("bordercolor", "c3cecc");

kick it on DotNetKicks.com   vote it on Web Development Community   411ASP.NET


Joining the Twitter Bandwagon

May 27, 2009 07:16 by agrace

Follow me on Twitter Well, I've finally succumbed to the World of Twitter. How did I ever live without it? Okay, sarcasm aside, it's fun to play with and what really sold me was Scott Hanselman's blog post on how it can provide us with an alternative to going through the 1-800 recorded messages from hell when trying to get customer support - the idea being that you have a fair chance of getting some attention the next time your cable acts up by mentioning it in Twitter. Apparently big companies are monitoring the big T by using its search facility. Ever wonder what's being said about you?

After signing up and spending an inordinate amount of time trying to conjure up something deep and meaningful under 140 characters, I downloaded TweetDeck. Then I signed up to http://bit.ly which basically provides the same URL-shortening service as http://tinyurl.com, except better. I have yet to check out TBuzz, Twitmatic, Twubs, TweetMic, Tweekdoku, Twadget, Twit4Live, Twittervision, Twitterholic........

Follow me on Twitter

It is estimated that there are currently over six million people "tweeting". More and more developers are using it to break news items and get quick answers to coding problems. You can find some of the top names in development circles using Twitter here.

Follow me on Twitter! I will include the Twitter logo in the new CodersBarn facelift.... soon.

vote it on Web Development Community


Tags: , ,
Categories: twitter
Actions: E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed

SP2 Available for Vista and Windows 2008

May 26, 2009 08:05 by agrace

Service Pack Expert As usual, I get the latest Microsoft news from Mary-Jo Foley's blog. As a developer, there was a time when I would be rushing to check a new Service Pack's feature list to see if some bug or other was finally resolved. Since the SharePoint SP2 fiasco I'm exercising a little more restraint in applying SPs. I notice that Microsoft is going to push this out with automatic updates on May 30 - luckily SPs are not applied automatically in the SharePoint world. For everybody else, do the sensible thing and apply it to a VM before you hit your development or production machines with it :-)

SP2 Download Links:
* 32-bit
* 64-bit
* ISO

kick it on DotNetKicks.com   vote it on Web Development Community


Tags:
Categories:
Actions: E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed

Visual Studio 2010 Beta 1 Arrives!

May 20, 2009 20:47 by agrace

The entire blogosphere is buzzing over this release. I got to try it out for the first time last week while working though some of the hands-on labs at TechEd 2009 in Los Angeles. I was so engrossed in the lab content that I didn't pay it a lot of attention. BTW, Scott Hanselmann gave a great session entitled "Whirlwind Tour around .NET 4 (and Visual Studio) Beta 1 - check it out.

I decided to try it out this evening on a Windows Server 2008 VM, which had SQL Server 2005 installed. Everything went smoothly until after the first reboot when it bombed out. Then I remembered that there is a new Windows 4.5 Installer out so I downloaded that and tried again. Success! It only took about thirty minutes on a fairly fast machine.

VS 2010 Beta 1

I'm using VMWare Workstation, but if you are using Microsoft VMs then there is a really helpful video on Channel 9 which describes the download and installation of VS 2010 in depth. Either way, be sure to grab the installer first.

  * Visual Studio 2010 and .NET Framework 4 Beta 1Downloads

  * Visual Studio 2010 Product Information

What's in the works for the SharePoint Development IDE

Many months ago, the MVPs were invited to Redmond and shown the next generation of SharePoint development tools. Needless to say they were bound to a secrecy agreement and ever since have remained as tight-lipped as a duck's arse and that's watertight. So I was really dying to check out what SharePoint project templates might appear - unfortunately all I got was a blank box. However, it looks like the red-suspendered marketing folks have revealed some information on this in a VS 2010 marketing "overview" brochure (link at end of post). SharePoint goodies include:

"Project templates for list definitions, list instances, site definitions, workflows, event receivers, Business Data Catalog models, and content types"

So, it looks like the extensions are finally baked in where they belong. This is good news considering the the latest CTP of VSeWSS 1.3 has some problems with the 64-bit architecture.

"The feature and package designers in Visual Studio 2010 allow you to determine how your SharePoint application packages are assembled and deployed... without having to manually write the XML for the .wsp deployment packages."

Some further research revealed that much of this info was already out there if you knew where to look. So why were the SharePoint presenters at TechEd acting like they held the secrets of the universe? There was an announcement on some aspects of this last February on Somesegar's Blog - here you will find a link to a video interview with Reza Chitsaz, Senior Program Manager working on Office and Sharepoint tooling - this came out last November!

VS 2010 Beta 1

All hype aside, the new WPF-based IDE is really slick and I'm really looking forward to trying out some of the new Ajax 4.0 client controls :-)

The new SharePoint 2007 Marketing Website

VisualStudio2010_ProductOverview.pdf (1.03 mb)

kick it on DotNetKicks.com   vote it on Web Development Community