Reputation: 5592
This is complicated to explain and probably very simple to do.
1) I have a dictionary . (Variable _output)
2) Inside the NotificationWrapper i have a list.
3) Inside this list i have some requirements that i need to be matched.
4) If those requirements are matched i want to return the NotificationWrapper from the dictionary. (_output.value)
I tried something like this:
var itemsToSend =
_output.Where(
z => z.Value.Details.Where(
x => DateTime.Now >= x.SendTime &&
x.Status == SendStatus.NotSent &&
x.TypeOfNotification == UserPreferences.NotificationSettings.NotificationType.Email
)
).Select().ToList();
So i want the _output entries that matches the condition inside the entry itself. So for each entry i loop through, i check the values inside the list in that entry to see if its been sent or not. If it hasn't been sent, then i want to return that _output.value item. itemsToSend should contain _output entries that hasn't been sent. (Not some values inside _output.value.xxx)
Upvotes: 1
Views: 3775
Reputation: 31757
Compiled in Google Chrome :)
var itemsToSend = _output
.Values
.Where(n => n.Details.Any(
x => DateTime.Now >= x.SendTime &&
x.Status == SendStatus.NotSent &&
x.TypeOfNotification == UserPreferences.NotificationSettings.NotificationType.Email))
.ToList();
I.e. I think you're looking for Any()
.
Upvotes: 5
Reputation: 27357
Something like this?
public partial class Form1 : Form
{
public Number SomeNumber { get; set; }
public Form1()
{
InitializeComponent();
var _output = new Dictionary<int, List<Number>>
{
{
1, new List<Number>
{
new Number {details = new Number.Details{a = true, b = true, c = true}},
new Number {details = new Number.Details{a = false, b = false, c = false}},
new Number {details = new Number.Details{a = true, b = true, c = false}},
new Number {details = new Number.Details{a = false, b = false, c = false}},
new Number {details = new Number.Details{a = true, b = true, c = true}},
}
}
};
var itemsToSend = (from kvp in _output
from num in kvp.Value
where num.details.a && num.details.b && num.details.c
select num).ToList();
}
}
public class Number
{
public Details details { get; set; }
public class Details
{
public bool a;
public bool b;
public bool c;
}
}
Upvotes: 0