// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex { using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics.Contracts; using System.Linq; using System.Reactive.Linq; using System.Text; using System.Threading.Tasks; using Perspex.Controls; public static class Selectors { public static Match Select(this Control control) { Contract.Requires(control != null); if (control is T) { return new Match { Control = control, }; } else { return null; } } public static Match Class(this Match selector, string name) { Contract.Requires(name != null); if (selector != null) { IObservable match = Observable .Return(selector.Control.Classes.Contains(name)) .Concat(selector.Control.Classes.Changed.Select(e => selector.Control.Classes.Contains(name))); return new Match { Control = selector.Control, Observable = match, Previous = selector, }; } else { return null; } } public static Match PropertyEquals(this Match selector, PerspexProperty property, T value) { Contract.Requires(property != null); if (selector != null) { IObservable match = selector.Control.GetObservable(property).Select(x => object.Equals(x, value)); return new Match { Control = selector.Control, Observable = match, Previous = selector, }; } else { return null; } } } }