public void BTest() { string text = "00001111"; byte value = ConvertCode.BinaryToByte(text); Assert.AreEqual(value, 15); text = "1111"; value = ConvertCode.BinaryToByte(text); Assert.AreEqual(value, 15); text = "11110000"; value = ConvertCode.BinaryToByte(text); Assert.AreEqual(value, 0xF0); text = "1111000"; value = ConvertCode.BinaryToByte(text); Assert.AreEqual(value, 0x78); text = "0"; value = ConvertCode.BinaryToByte(text); Assert.AreEqual(value, 0x00); text = "11111111"; value = ConvertCode.BinaryToByte(text); Assert.AreEqual(value, 0xFF); }
public void HexToStringTest() { string inSting = ConvertCode.StringToHex("初始化为适当的值", Separate.OX); string expected = "初始化为适当的值"; string actual = ConvertCode.HexToString(inSting); Assert.AreEqual(expected, actual); }
public void StringToHexTest() { string str = "TODO: 初始化为适当的值"; Separate se = Separate.Bank; string actual = ConvertCode.StringToHex(str, se); string expected = ConvertCode.HexToString(actual); Assert.AreEqual(expected, str); }
public void StringToBtyesTest() { string inSting = "初始化为适当的值"; byte[] actual = ConvertCode.StringToBtyes(inSting); string text = ConvertCode.BytesToString(actual, Separate.None); Assert.AreEqual(text, inSting); }
public void HexToBtyesTest() { string inSting = "0X01 0X02 0X03 0X04 0x05 0X06 0X07 0X08 "; byte[] expected = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; byte[] actual = ConvertCode.HexToBtyes(inSting); Assert.AreEqual(expected.ArrayAreEqual(actual), true); }
public void BytesToStringTest() { byte[] bytes = new byte[] { 1, 2, 3 }; Separate se = new Separate(); string actual = ConvertCode.BytesToString(bytes, se); byte[] expected = ConvertCode.StringToBtyes(actual); Assert.AreEqual(expected.ArrayAreEqual(bytes), true); }
private void ConvertFiles(FileInfo project, DirectoryInfo dest, String basename) { DirectoryInfo sourceDir = project.Directory; DirectoryInfo winformsPath = dest.PathCombineDirectory(basename, $"{basename}.Desktop", "UserInterface"); DirectoryInfo modulesPath = dest.PathCombineDirectory(basename, $"{basename}.Core", "Helpers"); DirectoryInfo classPath = dest.PathCombineDirectory(basename, $"{basename}.Core", "Services"); winformsPath.Create(); modulesPath.Create(); classPath.Create(); ConvertCode convertCode = new ConvertCode(); using (TextReader reader = project.OpenText()) { while (reader.Peek() > 0) { String line = reader.ReadLine(); if (String.IsNullOrEmpty(line)) { return; } String[] kvm = line.Split('='); switch (kvm.FirstOrDefault()) { case "Class": // Last part Only String classFile = kvm.Last().Split(';').Last().Trim(); FileInfo classFilePath = sourceDir.PathCombineFile(classFile); Debug.WriteLine($"class:{classFile}"); convertCode.ParseFile(classFilePath, dest, classPath); break; case "Module": // Last part only String moduleFile = kvm.Last().Split(';').Last().Trim(); FileInfo moduleFilePath = sourceDir.PathCombineFile(moduleFile); Debug.WriteLine($"module:{moduleFile}"); convertCode.ParseFile(moduleFilePath, dest, modulesPath); break; case "Form": // Form files go to desktop String formFile = kvm[1]; FileInfo formFilePath = sourceDir.PathCombineFile(formFile); Debug.WriteLine($"Form:{formFile}"); convertCode.ParseFile(formFilePath, dest, winformsPath); break; } } } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { ConvertCode = parameter.GetValueAt <string>(0); if (ConvertCode.IsNullOrWhiteSpace()) { return(value); } if (this.ConvertOperation == null) { this.ConvertOperation = ConstructOperation(value, targetType); } return(this.ConvertOperation.DynamicInvoke(value)); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string convertCode = parameter.GetValueAt <string>(0); ConvertCode = convertCode.IsNullOrWhiteSpace() ? ConvertCode : convertCode; if (ConvertCode.IsNullOrWhiteSpace()) { return(value); } if (this.ConvertOperation == null) { this.ConvertOperation = ConstructOperation(ConvertCode, value); } return(System.Convert.ChangeType(ConvertOperation.ExecuteFunc(value), targetType)); }
public void ByteToBinaryTest() { byte data = 0; string expected = "00000000"; string actual = ConvertCode.ByteToBinary(data); Assert.AreEqual(expected, actual); data = 255; expected = "11111111"; actual = ConvertCode.ByteToBinary(data); Assert.AreEqual(expected, actual); data = 168; expected = "10101000"; actual = ConvertCode.ByteToBinary(data); Assert.AreEqual(expected, actual); }
public void BytesToBinaryTest() { byte[] bytes = new byte[] { 1, 2, 3 }; Separate se = Separate.None; string expected = "000000010000001000000011"; string actual = ConvertCode.BytesToBinary(bytes, se); Assert.AreEqual(expected, actual); se = Separate.Bank; expected = "00000001 00000010 00000011 "; actual = ConvertCode.BytesToBinary(bytes, se); Assert.AreEqual(expected, actual); se = Separate.Ox; expected = "00000001 00000010 00000011 "; actual = ConvertCode.BytesToBinary(bytes, se); Assert.AreEqual(expected, actual); se = Separate.OX; expected = "00000001 00000010 00000011 "; actual = ConvertCode.BytesToBinary(bytes, se); Assert.AreEqual(expected, actual); }
public void BytesTo16Test() { byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Separate se = Separate.Ox; string expected = "0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 "; string actual = ConvertCode.BytesTo16(bytes, se); Assert.AreEqual(expected, actual); se = Separate.OX; expected = "0X01 0X02 0X03 0X04 0X05 0X06 0X07 0X08 "; actual = ConvertCode.BytesTo16(bytes, se); Assert.AreEqual(expected, actual); se = Separate.Bank; expected = " 01 02 03 04 05 06 07 08"; actual = ConvertCode.BytesTo16(bytes, se); Assert.AreEqual(expected, actual); se = Separate.None; expected = "0102030405060708"; actual = ConvertCode.BytesTo16(bytes, se); Assert.AreEqual(expected, actual); }
public void ConvertCodeConstructorTest() { ConvertCode target = new ConvertCode(); }