本文整理汇总了C#中Subject.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.GroupBy方法的具体用法?C# Subject.GroupBy怎么用?C# Subject.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.GroupBy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildnewBrokersSubject
/// <summary>
/// Compose a Subject that tracks each broker in the cluster. Always replay all known brokers.
/// </summary>
/// <returns></returns>
private ISubject<BrokerMeta, BrokerMeta> BuildnewBrokersSubject()
{
var subj = new Subject<BrokerMeta>();
var pipeline =
// group by BrokerMeta
subj.GroupBy(e => e).
// select
Select(g =>
{
// we only want one per Broker
var gg = g.DistinctUntilChanged().Replay(1, Scheduler);
gg.Connect();
return gg;
}).
Replay(Scheduler);
pipeline.Connect();
var pipeline2 = pipeline.Merge();
return Subject.Create(subj, pipeline2);
}
示例2: GroupBy
public void GroupBy()
{
SetScehdulerForImport();
var subject = new Subject<int>();
RecordObserver<int> a = null;
RecordObserver<int> b = null;
RecordObserver<int> c = null;
subject.GroupBy(x => x % 3)
.Subscribe(x =>
{
if (x.Key == 0)
{
a = x.Record();
}
else if (x.Key == 1)
{
b = x.Record();
}
else if (x.Key == 2)
{
c = x.Record();
}
});
subject.OnNext(99);
subject.OnNext(100);
subject.OnNext(101);
subject.OnNext(0);
subject.OnNext(1);
subject.OnNext(2);
a.Values.IsCollection(99, 0);
b.Values.IsCollection(100, 1);
c.Values.IsCollection(101, 2);
UniRx.Scheduler.SetDefaultForUnity();
}
示例3: GroupBy
public void GroupBy()
{
var subject = new Subject<int>();
RecordObserver<int> a = null;
RecordObserver<int> b = null;
RecordObserver<int> c = null;
subject.GroupBy(x => x % 3)
.Subscribe(x =>
{
if (x.Key == 0)
{
a = x.Record();
}
else if (x.Key == 1)
{
b = x.Record();
}
else if (x.Key == 2)
{
c = x.Record();
}
});
subject.OnNext(99);
subject.OnNext(100);
subject.OnNext(101);
subject.OnNext(0);
subject.OnNext(1);
subject.OnNext(2);
a.Values.IsCollection(99, 0);
b.Values.IsCollection(100, 1);
c.Values.IsCollection(101, 2);
}
示例4: Should_notify_with_null_when_right_do_not_have_data
public void Should_notify_with_null_when_right_do_not_have_data()
{
var bets = new Subject<Currency>();
var ex = new Subject<ExRate>();
var betsWithExRate = from g in ex.GroupBy(x => x.Currency)
from b in bets.Where(b => b.Code == g.Key).WithLatest(g, (b, x) =>
{
b.ExRate = x.Rate;
return b;
})
select b;
var received = new List<Currency>();
using (betsWithExRate.Subscribe(i => received.Add(i)))
{
ex.OnNext(new ExRate { Currency = "CNY", Rate = null });
bets.OnNext(new Currency { Id = 1, Code = "CNY" });
ex.OnNext(new ExRate { Currency = "CNY", Rate = 2.5m });
ex.OnNext(new ExRate { Currency = "MYR", Rate = 2.5m });
bets.OnNext(new Currency { Id = 2, Code = "CNY" });
ex.OnNext(new ExRate { Currency = "CNY", Rate = 2.6m });
bets.OnNext(new Currency { Id = 3, Code = "CNY" });
Assert.AreEqual(3, received.Count);
Assert.AreEqual(null, received[0].ExRate);
Assert.AreEqual(2.5m, received[1].ExRate);
Assert.AreEqual(2.6m, received[2].ExRate);
}
}