public static string Describe(this IKeypadButtonState state) { var result = new StringBuilder(); if (state == null) { return(result.ToString()); } result.Append(state.Id); result.Append("="); switch (state.Pressed) { case true: result.Append("Pressed"); break; case false: result.Append("Released"); break; default: result.Append("?"); break; } return(result.ToString()); }
public static ReadOnlyKeypadButtonState CopyFrom(IKeypadButtonState source) { var result = new ReadOnlyKeypadButtonState { Id = source.Id, Pressed = source.Pressed }; return(result); }
public static ReadOnlyKeypadButtonState CopyFrom(IKeypadButtonState source) { var result = new ReadOnlyKeypadButtonState { Id = source.Id, Pressed = source.Pressed }; return result; }
public static bool Changed(this IKeypadButtonState current, IKeypadButtonState previous) { if (!string.Equals(current.Id, previous.Id)) { throw new ArgumentException("Button " + previous.Id + " does not match button " + current.Id); } if (previous.Pressed == null) { return(current.Pressed == true); } return(current.Pressed != previous.Pressed); }
public static bool Changed(this IKeypadButtonState current, IKeypadButtonState previous) { if (!string.Equals(current.Id, previous.Id)) { throw new ArgumentException("Button " + previous.Id + " does not match button " + current.Id); } if (previous.Pressed == null) { return current.Pressed == true; } return current.Pressed != previous.Pressed; }
public static XElement ToXElement(this IKeypadButtonState state, string nodeName = "Button") { var result = new XElement(nodeName); if (state.Id != null) { result.Add(new XAttribute("Id", state.Id)); } if (state.Pressed != null) { result.Add(new XAttribute("Pressed", state.Pressed)); } return(result); }
public void ConvertButtonsWorks(byte[] data, IKeypadButtonState[] expected) { var actual = BinaryConversions.ConvertButtons(data).ToArray(); Assert.That(actual.Length, Is.EqualTo(expected.Length)); foreach (var actualButton in actual) { var expectedButton = expected.FirstOrDefault(x => x.Id == actualButton.Id); Assert.That(expectedButton, Is.Not.Null); Assert.That(actualButton.Pressed, Is.EqualTo(expectedButton.Pressed)); } }
public static IKeypadButtonState Copy(this IKeypadButtonState state) { return(ReadOnlyKeypadButtonState.CopyFrom(state)); }