Windows azure & WordPress

I had a minor down time due to a failing WordPress plugin update. I had to manually delete the failing plugins using the FTP account which is hidden inside the publish profile XML which you can download. Now I manually have to reinstall those plugins.



Alternative to IEnumerable for read-only collections

.NET 4.5 introduced a new interface which is great if you want to expose a collection as readonly.

The problem with IEnumerable<T> is that it’s forward only. i.e. there is no guarantee that you can traverse it multiple times. The collection size might also be unknown, depending on the implementation.

So if you want to expose a collection which can be traversed multiple times and where the size is know there is as of .NET 4.5 another alternative. And that’s IReadOnlyList<T>. It inherits another new interface called IReadOnlyCollection<out T>.

Code

public interface IReadOnlyCollection<out T> 
      : IEnumerable<T>, 
        IEnumerable
{
    int Count { get; }
}
public interface IReadOnlyList<out T> 
      : IReadOnlyCollection<T>
      , IEnumerable<T>
      , IEnumerable
{
    T this[int index] { get; }
}

Usage example

public class MyRepository
{
    public IReadOnlyList<User> FindUsers(string lastName)
    {
        // [...]
    }

    // [...]
}



Throwing exceptions

Throwing exceptions is in itself trivial. Just invoke throw with an exception object. But when should you throw? Should you create a new exception or rethrow an old one? What should you include in the exception info?

Continue Reading




What are exceptions?

This blog has been quiet for a while. I am currently writing a book about localization. Me and my partner is also getting close to release of our new startup. One of it’s features is to automatically catch unhandled exceptions and send them to a webservice for analytics. But to take full advantage of that you’ll have to use a set of exception handling best practices. I’m therefore going to write a set of exception articles. The series will end with the release of our service.

Continue Reading


Pages:1234567...14