本文整理匯總了C#中Windows.ApplicationModel.DataTransfer.DataPackage.SetAsyncDataProvider方法的典型用法代碼示例。如果您正苦於以下問題:C# DataPackage.SetAsyncDataProvider方法的具體用法?C# DataPackage.SetAsyncDataProvider怎麽用?C# DataPackage.SetAsyncDataProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.ApplicationModel.DataTransfer.DataPackage
的用法示例。
在下文中一共展示了DataPackage.SetAsyncDataProvider方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SetAsyncDataProvider_ReturnsValueFromSyncTask
public async Task SetAsyncDataProvider_ReturnsValueFromSyncTask()
{
DataPackage dataPackage = new DataPackage();
dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, (formatId, deadline) =>
{
return Task.FromResult<object>("Test text");
});
DataPackageView dataPackageView = dataPackage.GetView();
string result = await dataPackageView.GetTextAsync();
Assert.AreEqual("Test text", result);
}
示例2: SetAsyncDataProvider_ReturnsValueFromAsyncTask
public async Task SetAsyncDataProvider_ReturnsValueFromAsyncTask()
{
DataPackage dataPackage = new DataPackage();
dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, async (formatId, deadline) =>
{
await Task.Delay(200);
return "Test text";
});
DataPackageView dataPackageView = dataPackage.GetView();
string result = await dataPackageView.GetTextAsync();
Assert.AreEqual("Test text", result);
}
示例3: SetAsyncDataProvider_PassesDeadlineToMethod
public async Task SetAsyncDataProvider_PassesDeadlineToMethod()
{
DataPackage dataPackage = new DataPackage();
DateTimeOffset deadlineValue = DateTimeOffset.MinValue;
dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, (formatId, deadline) =>
{
deadlineValue = deadline;
return Task.FromResult<object>("Test text");
});
DataPackageView dataPackageView = dataPackage.GetView();
string result = await dataPackageView.GetTextAsync();
Assert.AreNotEqual(DateTimeOffset.MinValue, deadlineValue);
}
示例4: SetAsyncDataProvider_PassesFormatIdToMethod
public async Task SetAsyncDataProvider_PassesFormatIdToMethod()
{
DataPackage dataPackage = new DataPackage();
string formatIdValue = null;
dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, (formatId, deadline) =>
{
formatIdValue = formatId;
return Task.FromResult<object>("Test text");
});
DataPackageView dataPackageView = dataPackage.GetView();
string result = await dataPackageView.GetTextAsync();
Assert.AreEqual(StandardDataFormats.Text, formatIdValue);
}