Xamarin:不确定使用DriveFile.Open投射什么 [英] Xamarin: Unsure what to cast using DriveFile.Open
本文介绍了Xamarin:不确定使用DriveFile.Open投射什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图查找关于Xamarin的DriveFile.Open的文档,但是仍然无法找到要从下面的代码中返回声明的类。
var pendingResult = driveFile.Open(..,..,..)
var obj = pendingResult.await();
在Android文档中,要投射到的类为
DriveContents driveContents = driveContentsResult.getDriveContents();
但是我找不到名为DriveContentsResult的类。
OnResult 回调)
解决方案 pre>
Non-Async way (using
解决方案 pre>
driveFile.Open(_googleApiClient,DriveFile.ModeReadOnly,null).SetResultCallback(this);
会调用 onResult
,您可以投射结果:
pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ var contentResults =(结果).JavaCast< IDriveApiDriveContentsResult>();
var driveContent = contentResults.DriveContents;
D.WriteLine(driveContent.DriveId);
$ b
异步方式:
var driveContentResult = driveFile.OpenAsync(_googleApiClient,DriveFile.ModeReadOnly,null).ContinueWith((resultTask)=>
{
var driveContentResults = resultTask.Result;
var driveContent = driveContentResults.DriveContents;
D.WriteLine(driveContent.DriveId);
});
I tried to lookup the documentation about DriveFile.Open for Xamarin but still can't find the class to cast the return statement from the code below
var pendingResult = driveFile.Open(.. , .., ..)
var obj = pendingResult.await();
On Android Documentation, the class to be casting to is
DriveContents driveContents = driveContentsResult.getDriveContents();
But i can't find the Class called DriveContentsResult.
解决方案
Non-Async way (using OnResult
callback)
driveFile.Open(_googleApiClient, DriveFile.ModeReadOnly, null).SetResultCallback(this);
Will call onResult
and there you can cast the result:
void IResultCallback.OnResult(Java.Lang.Object result)
{
var contentResults = (result).JavaCast<IDriveApiDriveContentsResult>();
var driveContent = contentResults.DriveContents;
D.WriteLine(driveContent.DriveId);
}
Async way:
var driveContentResult = driveFile.OpenAsync(_googleApiClient, DriveFile.ModeReadOnly, null).ContinueWith((resultTask) =>
{
var driveContentResults = resultTask.Result;
var driveContent = driveContentResults.DriveContents;
D.WriteLine(driveContent.DriveId);
});
这篇关于Xamarin:不确定使用DriveFile.Open投射什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文