Properties with property changed event, part 3

A while ago, I talked about how to write basic events for changed properties, and about the INotifyPropertyChanged interface. There is a third way to manage events, which is especially useful when your class has many events, but you expect a very low number of them to be actually handled.

As discussed before, every EventHandler stored in your object takes up space, which is a bit of a waste if most of those will be null. But events allow you to implement the add and remove methods yourself, so you can choose where to store the EventHandler delegate.

One way to do that is through the System.ComponentModel.EventHandlerList class. System.ComponentModel.Component exposes an Events property of this type, which is used by all classes inheriting from Component, including all Windows Forms controls.

See my U2U blog for a complete example, featuring a CueBannerTextBox (like the Internet Explorer 7 search box) with a CueBanner property and a CueBannerChanged event.

Technorati Tags: , , , , ,

Sending the LINQ To SQL log to the debugger output window

I was playing with LINQ To SQL (again) this evening, and I thought: why can’t I see the generated SQL statments in my debugger output window?

The DataContext.Log property is a great help to learn writing LINQ To SQL queries. All you need to do is assign a TextWriter to it, and you get to see al the SQL statements generated by the data context. But where do you send them to? Console.Out is an option, but you probably don’t want that in a release build. Furthermore, it doesn’t quite work for Windows services or ASP.NET applications. That’s why I wrote DebuggerWriter, an implementation of TextWriter that writes to the debugger log.

Find the code at my U2U Blog.

Compiling Regular Expressions

Update your bookmarks, new posts on .NET related stuff will be posted to http://www.u2u.info/Blogs/Kris/. The first new one to appear there is all about compiling regular expressions in .NET, with a free compiler tool to download. Enjoy reading.

WPF/E preview and new Expression designers released

Microsoft released the first CTP for WPF/E, short for Windows Presentation Foundation/Everywhere, a WPF subset to run in browsers (Firefox and IE on Windows, Firefox and Safari on the Mac). Broadly available for customers in the first half of 2007, “WPF/E” experiences will require a lightweight browser plug-in made freely available by Microsoft.

Just in case you haven’t figured out yet who they are competing against, Michael Swanson released a free Macromedia Flash to WPF/E converter

Also this week, Microsoft released Expression Blend Beta 1 (formerly known as Expression Interactive Designer, a graphical WPF XAML editor) and Expression Design December 2006 CTP (formerly known as Expression Graphic Designer).

Expression Blend looks good, though the first thing I did was change the default dark theme to the light theme, and decrease the workspace zoom to 90%. I need a bigger screen…

Paint.NET V3 Beta 1 available

Rick released the first beta for Paint.NET V3. This version is now feature complete, and all known bugs have been fixed. The coolest new feature in this release is a Perlin noise based clouds renderer, with – as usual – a very easy to use configuration panel.

I’d say it’s about time you uninstall that cracked Photoshop!

Linq to XSD preview released

Last Monday, the Microsoft XML Team released the first Linq to XSD preview.

While the LINQ to XML programmer operates on generic XML trees, the LINQ to XSD programmer operates on typed XML trees — instances of .NET types that model the XML types of a specific XML schema (XSD). […] LINQ to XSD is integrated into Visual Studio; so you just tag an XML schema as [a] ‘LINQ to XSD schema’, build your project, and the automatically derived object model is then part of your solution — just as if XML schemas were .NET types.

I only had a quick look, but I have to say it looks very promissing! Send them your feedback, but hurry, I want this to be included in Visual Studio Orcas.

Creating a Data Access Layer with Linq to SQL, part 2

Last time, we looked at how Linq To SQL might impact how we think about what a Data Access Layer (DAL) is, based on the dependencies between assemblies. This time, we’ll take a different approach: let’s look at typical Linq to SQL code, and try to decide where to put it. I’ll use a code sample from the “DLinq Overview for CSharp Developers” document included in the Linq May CTP (in C# 3.0, but the same applies to VB9).

Continue reading ‘Creating a Data Access Layer with Linq to SQL, part 2′



Follow

Get every new post delivered to your Inbox.