本文整理汇总了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);
}