Site Archives c#

Mixins for .NET


Mixins are missing from C#. There are lots of examples of emulating mixins and some really good ideas. The best ideas assume the use of C# 4.0 and use the ConditionalWeakTable class. However none of the ideas I could find were truly generic. This post is about a generic mixins mechanism for .NET and provides […]

A good word for ILSpy


Back in the day, Lutz Roeder created the really useful utility Reflector. He later sold it to Red Gate who, reasonably, tried to make money from it by removing the free version. Uproar ensued. Although RG backed away from their initial position and now make available a free version, the ILSpy project came to the […]

Inter-process communications


WCF is a pretty comprehensive communications framework but is daunting to use. Even for practitioners experienced in the art there is lots do each time a new project is started. Lots of options, lots of configuration most of which is daunting to the uninitiated. I’ve used WCF in the past to create web applications independent […]

.NET Win 7-style folder select dialog


Sometimes it’s necessary to allow a user to select a folder not a file. The .NET FolderBrowserDialog (part of System.Windows.Forms) is showing its age. With Vista came a new folder selection dialog based on the OpenFileDialog but the Vista-style dialog has not been added to .NET. This post includes code (c#) to display the Vista/Win […]

Auto update for EC2 security groups


Access to services on an Amazon Web Services EC2 instance is controlled by security groups. These allow you to have, say, port 80 available to anyone but have other ports only accessible from specific IP address(es). If the IP address supplied by your ISP is dynamic or, at least, not not static you can find […]

LINQ: Let me re-iterate


In his post Generalized IEnumerable to chunked IEnumerable Steve Gilham shows how an IEnumerable can be chopped into chunks and processed as part of a LINQ query. His example is great because it provides an extension method to chop any IEnumerable (for example a file stream) into chunks which are to be processed independently. In […]

LINQ: it can grow on trees


The IEnumerable interface underpins LINQ. It’s the contract that makes LINQ queries composable. I think the whole link thing is great (see earlier post) but is constrained to to dealing with flat data. Sure you can group but if you need groups nested three deep then you have to know this in advance. Hierarchical structures […]

OfficeOpenXml: Agile Encryption


Recently danyelljc contacted me to point out that the code associated with an earlier article did not include an example of using the “Agile Encryption” (see section 2.3.4.10 – 2.3.4.15 in MS-OFFCRYPTO) which is used as the default encryption in Office 2010. This post corrects my omission.

Enumeration list box


As the name suggests, the enumeration list box is a list box which shows and sets enumeration values using radio buttons. But this post is not really about the ListBox or RadioButton. It about how to populate a list box (displaying radio buttons or pictures of cherubs) from an enumeration. There’s a project to accommpany […]

Loading from and saving property values to a config file


Not an inspiring title, after all it’s not difficult to read from or save to a configuration file. That’s true, but this post is about a technique that’s useful in many scenarios but especially when using the MVVM pattern. It involves very little code: a custom attribute and three extension methods. In the System.Configuration namespace […]