C#-IReliableDictionary上的Linq查询
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#-IReliableDictionary上的Linq查询,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3088字,纯文字阅读大概需要5分钟。
内容图文
我已经做了很多查找和弄乱代码的工作,但还没有找到对IReliableDictionary进行Linq查询的方法.我知道它与标准IDictionary不同,但是我很好奇是否有人有幸.我开始认为不幸的是这是不可能的.
解决方法:
当前,没有正常方法对可靠的字典进行linq查询.话虽如此,您可以做一些事情.如前所述,CreateEnumerableAsync方法存在的原因是因为服务结构将可靠的字典分页到磁盘,但是如果您知道基础集合很小并且对性能没有影响,那么以下类将起作用.
public static class AsyncEnumerableExtensions
{
/// <summary>
/// Converts the collection to a list
/// </summary>
/// <typeparam name="TValType">value type of the collection</typeparam>
/// <param name="enumerator">enumerator to convert</param>
/// <param name="ct">cancellation token for the async operations</param>
/// <param name="tx">tx to enforce that this is called in a transactional context</param>
/// <returns>a list containing all elements in the origin collection</returns>
public static async Task<IList<TValType>> ToListAsync<TValType>(
this IAsyncEnumerator<TValType> enumerator,CancellationToken ct, ITransaction tx)
{
IList<TValType> ret = new List<TValType>();
while (await enumerator.MoveNextAsync(ct).ConfigureAwait(false))
{
ret.Add(enumerator.Current);
}
return ret;
}
/// <summary>
/// Converts the collection to a list
/// </summary>
/// <typeparam name="TValType">value type of the collection</typeparam>
/// <param name="enumerator">enumerator to convert</param>
/// <param name="tx">tx to enforce that this is called in a transactional context</param>
/// <returns>a list containing all elements in the origin collection</returns>
public static Task<IList<TValType>> ToListAsync<TValType>(
this IAsyncEnumerator<TValType> enumerator, ITransaction tx)
{
return enumerator.ToListAsync(CancellationToken.None,tx);
}
/// <summary>
/// Converts the collection to a list
/// </summary>
/// <typeparam name="TValType">value type of the collection</typeparam>
/// <param name="enumerable">enumerator to convert</param>
/// <param name="ct">cancellation token for the async operations</param>
/// <param name="tx">tx to enforce that this is called in a transactional context</param>
/// <returns>a list containing all elements in the origin collection</returns>
public static Task<IList<TValType>> ToListAsync<TValType>(this IAsyncEnumerable<TValType> enumerable,
CancellationToken ct, ITransaction tx)
{
return enumerable.GetAsyncEnumerator().ToListAsync(ct,tx);
}
/// <summary>
/// Converts the collection to a list
/// </summary>
/// <typeparam name="TValType">value type of the collection</typeparam>
/// <param name="enumerable">enumerator to convert</param>
/// <param name="tx">tx to enforce that this is called in a transactional context</param>
/// <returns>a list containing all elements in the origin collection</returns>
public static Task<IList<TValType>> ToListAsync<TValType>(this IAsyncEnumerable<TValType> enumerable, ITransaction tx)
{
return enumerable.GetAsyncEnumerator().ToListAsync(tx);
}
}
您还可以实现自己的自定义枚举器和扩展方法,以对数据执行linq查询之类的高效操作.我写了一些我想发布的内容,但他们首先需要润色.我有一个偷偷摸摸的感觉,服务结构团队可能已经在其中,但是如果发生或何时发生,您的猜测与我的一样好.
内容总结
以上是互联网集市为您收集整理的C#-IReliableDictionary上的Linq查询全部内容,希望文章能够帮你解决C#-IReliableDictionary上的Linq查询所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。