-
-
Notifications
You must be signed in to change notification settings - Fork 416
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I write this TryAsync
chain?
#956
Comments
In the If you look at the signature of the If you change the type of the PS: the |
@Malgefor Duh part 27! As usual, you've hit the nail on the head. I did actually think of that, and tried to convert private TryAsync<string> CreateNewFolder(string folderName, string parentFolderId, List<DriveFile> folders) {
if (folders.Any()) {
// Is there a neater way to return the existing folder's Id?
return TryAsync(() => Task.Run(() => folders.First().Id));
}
DriveFile newFolder = new() {
Name = folderName,
MimeType = "application/vnd.google-apps.folder",
Parents = new[] { parentFolderId }
};
FilesResource.CreateRequest command = _service.Files.Create(newFolder);
return TryAsync(async () => {
DriveFile folder = await command.ExecuteAsync();
return folder.Id;
});
} Thanks again for all the help. |
You don't have to do that Other than that maybe move the |
Not sure what you mean. I need to check if a folder with the given name already exists. Otherwise I would end up creating another folder with the same name. Thanks again. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I am writing some methods that work with the C# Google Drive API, and have most of them working. They return
TryAsync<T>
, and thanks to some great help from @Malgefor in another issue, I can chain them together.However, one method is causing me problems. It is supposed to create a new folder. Although Google Drive allows multiple files and folders to have the same name, our code is not going to. Therefore, the
CreateFolder
method first needs to check if a folder of that name exists, and if so, just return theId
. If it doesn't exist, then we are to create it and return theId
.I already have the following method working (implementation omitted as it's not relevant)...
...where the (badly-named in my opinion)
File
type is in theGoogle.Apis.Drive.v3
namespace, and refers to either a file or a folder.I also have a private method that checks the
folders
passed in to see if one by namedfolderName
already exists, creates a new one where needed and returns theId
(again, implementation omitted)...What I want to do is stick these together.
I tried the following...
...but this gives a compiler error on the call to
Bind
...The type arguments for method 'TryAsyncExtensions.Bind<A, B>(TryAsync, Func<A, TryAsync>)' cannot be inferred from the usage
...as well as a confusing (to me at least) compiler error on the
folders
variable at the end of that same line...Argument 3: cannot convert from 'int' to 'System.Collections.Generic.List<Google.Apis.Drive.v3.Data.File>'
That second error seems really weird, as if I hover over the
folders
variable, it clearly shows me that it is aList<File>
, so why it thinks it's anint
is beyond me. However, I suspect that if I can fix the first error, the second may go away.Anyone any idea what I'm doing wrong? Please let me know if I need to supply anything else. I tried to show as much code as I can,. without confusing the matter with implementation details.
Thanks
The text was updated successfully, but these errors were encountered: