本文整理汇总了C#中System.Stream.Map方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.Map方法的具体用法?C# Stream.Map怎么用?C# Stream.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Stream
的用法示例。
在下文中一共展示了Stream.Map方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: STextBox
public STextBox(Stream<string> setText, string initText, Cell<bool> enabled)
{
base.Text = initText;
List<IListener> listeners = new List<IListener>();
StreamSink<int> sDecrement = new StreamSink<int>();
Cell<bool> allow = setText.Map(_ => 1).OrElse(sDecrement).Accum(0, (b, d) => b + d).Map(b => b == 0);
StreamSink<string> sUserChanges = new StreamSink<string>();
this.SUserChanges = sUserChanges;
this.Text = sUserChanges.Gate(allow).OrElse(setText).Hold(initText);
TextChangedEventHandler textChangedEventHandler = (sender, args) =>
{
string text = base.Text;
this.Dispatcher.InvokeAsync(() => sUserChanges.Send(text));
};
this.TextChanged += textChangedEventHandler;
// Set the initial value at the end of the transaction so it works with CellLoops.
Transaction.Post(() => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = enabled.Sample()));
listeners.Add(setText.Listen(t =>
{
this.Dispatcher.InvokeAsync(() =>
{
this.TextChanged -= textChangedEventHandler;
base.Text = t;
this.TextChanged += textChangedEventHandler;
sDecrement.Send(-1);
});
}));
listeners.Add(Operational.Updates(enabled).Listen(e => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = e)));
this.disposeListeners = () =>
{
foreach (IListener l in listeners)
{
using (l)
{
}
}
};
}