Conversation started Apr 4, 2013 at 19:25.
Apr 4, 2013 19:25
@JohanLarsson it is interesting, but it was basically simple
Given a List<SomeClass> where SomeClass has a property that is List<Foo> FooList that has properties including Name, find all SomeClass where FooList matches or encapsulates a given TestList that is just a string[].
basically it collapsed to this:
foreach(var someClass in SomeClassList) { var someList = someClass.FooList.Select(x => x.Name); if(String.Join(",",someList.Intersect(testList)).OrderBy(x=>x).ToString().ToLowerInvariant() == String.Join(",",someList.OrderBy(x=>x)).ToString().ToLowerInvariant()) { /* do the things */ } }
list.Where(x=>TestList.Except(x.FooList.Select(y=>y.Name)).Any())
@MikeF really? That'll compare the two lists and find only the ones that match?
I haven't convinced myself this is correct yet, but something like that should be feasible
Ensuring that I only have the elements that are a subset of testList and are also the elements of someList, where testList may have more elements than someList, but someList will be completely contained in testList?
I'm all for a faster solution, but for me this was enough
"Except....Any" should behave as "is subset of"
Apr 4, 2013 19:31
Should I toss it up on SO? CodeReview?
I don't think so.
I'm all for "is there a better way to do this" but I don't think any of the SE really encourage that, per-se
But I obviously have a working solution
He had some mass of nested for loops and we originally attacked it with a dictionary of bools until I was like "this is too complicated, let's whiteboard it"
 
Conversation ended Apr 4, 2013 at 19:32.