private UIImage ApplyCustomTransformations(List <ITransformation <UIImage> > transformations, UIImage result) { if (result == null) { throw new ArgumentNullException("result"); } for (int i = 0; i < transformations.Count; i++) { ITransformation <UIImage> transformation = transformations[i]; UIImage newResult = transformation.Transform(result); if (newResult == null) { StringBuilder builder = new StringBuilder() .Append("Transformation ") .Append(transformation.Key) .Append(" returned null after ") .Append(i) .Append(" previous transformation(message).\n\nTransformation list:\n"); foreach (ITransformation <UIImage> t in transformations) { builder.Append(t.Key).Append('\n'); } // TODO Need a better way to invoke on main thread new NSObject().InvokeOnMainThread(() => { throw new NullReferenceException(builder.ToString()); }); return(null); } // TODO Check if result is disposed if (newResult == result) { m_Picasso.RunOnPicassoThread(() => { throw new InvalidOperationException("Transformation " + transformation.Key + " return input Bitmap but recycled it."); }); return(null); } // If the transformation returned a new bitmap ensure they recycled the original. // TODO Check if result is NOT disposed if (newResult != result) { m_Picasso.RunOnPicassoThread(() => { throw new InvalidOperationException("Transformation " + transformation.Key + " mutated input Bitmap but failed to recycle the original."); }); return(null); } result = newResult; } return(result); }