Tag: findall

链接通用列表扩展的方法

我有一个“复杂”类型的列表 – 一个具有一些字符串属性的对象。 List本身是另一个对象的属性,包含各种类型的对象,如此缩写类结构所示: Customer { public List Characteristics; . . . } Characteristic { public string CharacteristicType; public string CharacteristicValue; } 我希望能够为当前客户收集特定类型特征值的列表,我可以按如下步骤分两步完成: List interestCharacteristics = customer.Characteristics.FindAll( delegate (Characteristic interest) { return interest.CharacteristicType == “Interest”; } ); List interests = interestCharacteristics.ConvertAll( delegate (Characteristic interest) { return interest.CharacteristicValue; } ); 这很好,但似乎还有很长的路要走。 我确定我必须错过一个更简单的方法来获取这个列表,或者通过链接FindAll()和Convert()方法,或者我完全忽略的其他东西。 对于背景,我在.Net 2.0工作,所以我只限于.Net 2generics,而且特性类是外部依赖 – […]

在C#中为通用列表的FindAll添加参数

我有一个对象列表,我想用整数参数过滤 List objectList = new List(); // populate objectList with testObjects objectList.FindAll(GroupLevel0); private static bool GroupLevel0(testObject item) { return item._groupLevel == 0; } private class testObject { public string _FieldSQL = null; public int _groupLevel; } 我想要做的是让GroupLevel0接受一个整数作为参数,而不是硬编码为0.我在.NET 2.0中工作,所以lambda表达式是不行的。 甚至可以将参数传递给谓词吗? 谢谢,

使用Roslyn查找对方法的所有引用

我正在寻找扫描一组.cs文件,以查看哪些调用Nullable的Value属性(查找所有引用)。 例如,这将匹配: class Program { static void Main() { int? nullable = 123; int value = nullable.Value; } } 我发现了Roslyn并查看了一些样本,但其中许多已经过时且API非常庞大。 我该怎么做呢? 解析语法树后我陷入了困境。 这是我到目前为止: public static void Analyze(string sourceCode) { var tree = CSharpSyntaxTree.ParseText(sourceCode); tree./* ??? What goes here? */ }