Contract classes and nested types within interfaces

I’ve just been going through some feedback for the draft copy of the second edition of C# in Depth. In the contracts section, I have an example like this: [ContractClass(typeof(ICaseConverterContracts))] public interface ICaseConverter {     string Convert(string text); } [ContractClassFor(typeof(ICaseConverter))] internal class ICaseConverterContracts : ICaseConverter {     string ICaseConverter.Convert(string text)     {         Contract.Requires(text != null);         Contract.Ensures(Contract.Result<string>() != null);         return default(string);     }     private ICaseConverterContracts() {} } public class InvariantUpperCaseFormatter : ICaseConverter {     public string Convert(string text)      {         return text.ToUpperInvariant();     } } The point is to demonstrate how contracts can be specified for interfaces, and then applied automatically … Continue reading Contract classes and nested types within interfaces

MVP Again

I’m delighted to be able to announce that I’m now an MVP again. Google has reconsidered the situation and worked out a compromise: I now receive no significant gifts from Microsoft, and I’m not under NDA with them. While that precludes me from a lot of MVP activities, it removes any concerns to do with Google’s Code of Conduct. Basically my MVP status is truly just a token of Microsoft’s recognition of what I’ve done in the C# community – and that’s fine by me. When I announced that I’d been advised not to seek renewal, I was amazed at … Continue reading MVP Again

Migrating from Visual Studio 2010 beta 1 to beta 2 – solution file change required

Having installed Visual Studio 2010 beta 2 on my freshly-reinstalled netbook (now with Windows 7 and and SSD – yummy) I found that my solution file from Visual Studio 2010 beta 1 wasn’t recognised properly: double-clicking on the file didn’t do anything. Opening the solution file manually was absolutely fine, but slightly less convenient than being able to double-click. After a bit of investigation, I’ve found the solution. Manually edit the solution file, and change the first few lines from this: Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 10 to this: Microsoft Visual Studio Solution File, … Continue reading Migrating from Visual Studio 2010 beta 1 to beta 2 – solution file change required

Iterating atomically

The IEnumerable<T> and IEnumerator<T> interfaces in .NET are interesting. They crop up an awful lot, but hardly anyone ever calls them directly – you almost always use a foreach loop to iterate over the collection. That hides all the calls to GetEnumerator(), MoveNext() and Current. Likewise iterator blocks hide the details when you want to implement the interfaces. However, sometimes details matter – such as for this recent Stack Overflow question. The question asks how to create a thread-safe iterator – one that can be called from multiple threads. This is not about iterating over a collection n times independently … Continue reading Iterating atomically

Generic collections – relegate to an appendix?

(I tweeted a brief version of this suggestion and the results have been overwhelmingly positive so far, but I thought it would be worth fleshing out anyway.) I’m currently editing chapter 3 of C# in Depth. In the first edition, it’s nearly 48 pages long – the longest in the book, and longer than I want it to be. One of the sections in there (only 6 pages, admittedly) is a description of various .NET 2.0 collections. However, it’s mostly comparing them with the nongeneric collections from .NET 1.0, which probably isn’t relevant any more. I suspect my readership has … Continue reading Generic collections – relegate to an appendix?

MVP no more

It’s with some sadness that I have to announce that as of the start of October, I’m no longer a Microsoft MVP. As renewal time came round again, I asked my employer whether it was okay for me to renew, and was advised not to do so. As a result, while I enjoyed being awarded as an MVP, I’ve asked not to be considered for renewal this year. This doesn’t mean I’m turning my back on that side of software development, of course. I’m still going to be an active member of the C# community. I’m still writing the second … Continue reading MVP no more