What happened to SafeConvertAll in ServiceStack?

72 views Asked by At

I am looking at the ServiceStack.UseCases application, specifically the ImageResizer project. The code in Global.asax references an extension method called SafeConvertAll, which does not appear to be a part of SS any longer. What happened to this function and what should I use to replace it?

Thanks

1

There are 1 answers

0
mythz On BEST ANSWER

It's just a safe wrapper around ConvertAll to treat null collections as empty collections, it's been replaced with a much shorter Map() alias, e.g:

public object Get(Images request)
{
    return Directory.GetFiles(UploadsDir)
        .Map(x => x.SplitOnLast(Path.DirectorySeparatorChar).Last());
}

You can also use .Safe() to return an empty collection for null collections letting you safely use LINQ extension methods like .Select(), e.g:

public object Get(Images request)
{
    return Directory.GetFiles(UploadsDir)
      .Safe().Select(x => x.SplitOnLast(Path.DirectorySeparatorChar).Last());
}

ImageResizer has just been upgraded to v4.0.40 in this commit.