【发布时间】:2011-03-09 08:17:00
【问题描述】:
我有一个命名空间字符串,例如“Company.Product.Sub1.Sub2.IService”。 Sub1/Sub2 的计数可能不同,但通常它们是匹配的一部分 以 AssemblyFullname 为键,路径为值的字典。
现在我写了这段代码
string fullName = interfaceCodeElement.FullName;
var fullNameParts = interfaceCodeElement.FullName.Split('.').Reverse();
KeyValuePair<string, string> type = new KeyValuePair<string,string>();
foreach (var item in fullNameParts)
{
var match = references.Where(x => x.Key.Contains(item)).ToList();
if (match.Count > 0)
{
type = match[0];
break;
}
}
有效,但在我看来并不好看。
我用 linq 试过了,但我不知道怎么写。
var matches = from reference in refs
where reference.Key.Contains(fullNameParts.Reverse().
感谢您的帮助。
【问题讨论】:
标签: c# .net linq .net-3.5 lambda