private void UpdateMainValue() { MainValue = new SmartNumber { Value = projectContext.FlagsNumber.Value, NumericalBase = projectContext.NumericalBaseService, BitCount = projectContext.FlagsNumber.BitCount }; }
private void UpdateFlagValue() { FlagValue = new SmartNumber { Value = flagItem.Value, NumericalBase = numericalBaseService, BitCount = flagItem.Parent?.BitCount ?? 0 }; }
private static object RenderHexadecimal(SmartNumber smartNumber) { string xamlContent = smartNumber.ToString(); List <string> result = new List <string>(); bool isBegin = true; foreach (char c in xamlContent) { bool isDigit = char.IsDigit(c) || (c >= 'A' && c <= 'F'); if (isBegin) { if (isDigit && c != '0') { isBegin = false; result.Add($@"<Run Foreground=""Black"">{c}</Run>"); } else { result.Add(c.ToString()); } } else { if (isDigit) { result.Add($@"<Run Foreground=""Black"">{c}</Run>"); } else { result.Add(c.ToString()); } } } xamlContent = string.Join("", result); string xamlTextBlock = @" <TextBlock xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" Padding = ""5"" VerticalAlignment = ""Center"" HorizontalAlignment = ""Stretch"" Foreground = ""Gray""> {0} </TextBlock>"; xamlTextBlock = string.Format(xamlTextBlock, xamlContent); using (StringReader stringReader = new StringReader(xamlTextBlock)) using (XmlReader xmlReader = XmlReader.Create(stringReader)) return(XamlReader.Load(xmlReader)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { SmartNumber smartNumber = value as SmartNumber; if (smartNumber != null) { return(ConvertFromSmartNumber(smartNumber)); } return(null); }
public void does_not_add_zeroes_to_the_left_if_BitCount_is_more_then_real_digit_count() { SmartNumber smartValue = new SmartNumber { Value = 13, NumericalBase = NumericalBase.Decimal, BitCount = 16 }; string actual = smartValue.ToString(); Assert.That(actual, Is.EqualTo("13")); }
public void does_not_add_zeroes_to_the_left_if_BitCount_0() { SmartNumber smartValue = new SmartNumber { Value = 13, NumericalBase = NumericalBase.Hexadecimal, BitCount = 0 }; string actual = smartValue.ToString(); Assert.That(actual, Is.EqualTo("D")); }
public void returns_string_empty_if_numerical_base_is_None() { SmartNumber smartValue = new SmartNumber { Value = 13, NumericalBase = NumericalBase.None, BitCount = 16 }; string actual = smartValue.ToString(); Assert.That(actual, Is.Empty); }
public void groups_digits_by_two_with_padding() { SmartNumber smartValue = new SmartNumber { Value = 1000, NumericalBase = NumericalBase.Hexadecimal, BitCount = 16 }; string actual = smartValue.ToString(); Assert.That(actual, Is.EqualTo("03 E8")); }
public void adds_zeroes_to_the_left_if_BitCount_is_more_then_real_digit_count() { SmartNumber smartValue = new SmartNumber { Value = 13, NumericalBase = NumericalBase.Binary, BitCount = 8 }; string actual = smartValue.ToString(); Assert.That(actual, Is.EqualTo("0000 1101")); }
public void returns_only_zeros_if_value_is_zero_and_BitCount_is_8() { SmartNumber smartValue = new SmartNumber { Value = 0, NumericalBase = NumericalBase.Binary, BitCount = 8 }; string actual = smartValue.ToString(); Assert.That(actual, Is.EqualTo("0000 0000")); }
public void groups_digits_by_four_with_padding() { SmartNumber smartValue = new SmartNumber { Value = 93, NumericalBase = NumericalBase.Binary, BitCount = 8 }; string actual = smartValue.ToString(); Assert.That(actual, Is.EqualTo("0101 1101")); }
public void does_not_add_zeroes_to_the_left_if_PadLeft_is_false() { SmartNumber smartValue = new SmartNumber { Value = 13, NumericalBase = NumericalBase.Decimal, BitCount = 16, PadLeft = false }; string actual = smartValue.ToString(); Assert.That(actual, Is.EqualTo("13")); }
public void throws_if_NumericalBase_has_invalid_value() { SmartNumber smartValue = new SmartNumber { Value = 13, NumericalBase = (NumericalBase)1000, BitCount = 16, PadLeft = false }; Assert.Throws <ArgumentOutOfRangeException>(() => { smartValue.ToString(); }); }
protected override void DoExecute(object parameter) { NumericalBase numericalBase = projectContext.NumericalBaseService; SmartNumber numberSerializer = new SmartNumber { Value = projectContext.FlagsNumber.Value, NumericalBase = numericalBase, BitCount = projectContext.FlagsNumber.BitCount, GroupLength = 0, PadLeft = numericalBase == NumericalBase.Binary }; string text = numberSerializer.ToString(); Clipboard.SetText(text); }
private static object ConvertFromSmartNumber(SmartNumber smartNumber) { switch (smartNumber.NumericalBase) { case NumericalBase.None: case NumericalBase.Decimal: return(smartNumber.ToString()); case NumericalBase.Hexadecimal: return(RenderHexadecimal(smartNumber)); case NumericalBase.Binary: return(RenderBinary(smartNumber)); default: throw new ArgumentOutOfRangeException(); } }
private static object RenderBinary(SmartNumber smartNumber) { string xamlContent = smartNumber.ToString(); xamlContent = xamlContent.Replace("1", @"<Run Foreground = ""Black"">1</Run>"); string xamlTextBlock = @" <TextBlock xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" Padding = ""5"" VerticalAlignment = ""Center"" HorizontalAlignment = ""Stretch"" Foreground = ""Gray""> {0} </TextBlock>"; xamlTextBlock = string.Format(xamlTextBlock, xamlContent); using (StringReader stringReader = new StringReader(xamlTextBlock)) using (XmlReader xmlReader = XmlReader.Create(stringReader)) return(XamlReader.Load(xmlReader)); }