private void Write(AddAsyncMediaMethod method) { WriteSignature(method); using (_builder.IndentBraced) { _("if (Entity == null)"); using (_builder.IndentBraced) { _("Context.AddObject(Path, item);"); } _("else"); using (_builder.IndentBraced) { _("var lastSlash = Path.LastIndexOf('/');"); _("var shortPath = (lastSlash >= 0 && lastSlash < Path.Length - 1) ? Path.Substring(lastSlash + 1) : Path;"); _("Context.AddRelatedObject(Entity, shortPath, item);"); } _("Context.SetSaveStream(item, stream, closeStream, new DataServiceRequestArgs()"); _("{"); using (_builder.Indent) { _("ContentType = contentType"); } _("});"); _("if (!deferSaveChanges)"); using (_builder.IndentBraced) { _("return Context.SaveChangesAsync();"); } _("else"); using (_builder.IndentBraced) { _("var retVal = new global::System.Threading.Tasks.TaskCompletionSource<object>();"); _("retVal.SetResult(null);"); _("return retVal.Task;"); } } }