static Converter() { BoolConverter.Initialize(); CharConverter.Initialize(); ByteConverter.Initialize(); SByteConverter.Initialize(); Int16Converter.Initialize(); UInt16Converter.Initialize(); Int32Converter.Initialize(); UInt32Converter.Initialize(); Int64Converter.Initialize(); UInt64Converter.Initialize(); SingleConverter.Initialize(); DoubleConverter.Initialize(); DecimalConverter.Initialize(); BigIntegerConverter.Initialize(); BytesConverter.Initialize(); CharsConverter.Initialize(); StringConverter.Initialize(); StringBuilderConverter.Initialize(); DateTimeConverter.Initialize(); TimeSpanConverter.Initialize(); GuidConverter.Initialize(); MemoryStreamConverter.Initialize(); StreamConverter.Initialize(); }
public MarcTranslatedReader(IMarcReader r, String unicodeNormalizeStr) { reader = r; convert = new AnselToUnicode(); if (unicodeNormalizeStr.Equals("KC")) { unicodeNormalize = NormalizationForm.FormKC; } else if (unicodeNormalizeStr.Equals("KD")) { unicodeNormalize = NormalizationForm.FormKD; } else if (unicodeNormalizeStr.Equals("C")) { unicodeNormalize = NormalizationForm.FormC; } else if (unicodeNormalizeStr.Equals("D")) { unicodeNormalize = NormalizationForm.FormD; } else { unicodeNormalize = NormalizationForm.FormC; } }
public void PropertiesTest() { var converter = new CharConverter(); Assert.AreEqual(true, converter.AcceptsNativeType); Assert.AreEqual(typeof(char), converter.ConvertedType); }
public void CharConverterTest() { Assert.That(CharConverter.Convert('A'), Is.EqualTo("A")); Assert.That(CharConverter.Convert("B"), Is.EqualTo('B')); Assert.Throws(typeof(FieldConvertError), delegate { CharConverter.Convert("AB"); }); }
public void SetUp() { converter = new CharConverter(); DateTimeFormatInfo info = CultureInfo.CurrentCulture.DateTimeFormat; pattern = info.ShortDatePattern + " " + info.ShortTimePattern; }
/// <summary> /// Initialize logging category /// </summary> /// <param name="r"></param> /// <param name="unicodeNormalizeBool"></param> public MarcTranslatedReader(IMarcReader r, bool unicodeNormalizeBool) { reader = r; convert = new AnselToUnicode(); if (unicodeNormalizeBool) { this.unicodeNormalize = NormalizationForm.FormC; } }
public void ConvertFromStringTest() { var converter = new CharConverter(); Assert.AreEqual('a', converter.ConvertFromString("a")); Assert.AreEqual('a', converter.ConvertFromString(" a ")); converter.ConvertFromString(null); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// typeconverter.ConvertTo<int>(value); /// </example> /// </summary> public static T ConvertTo <T>(this CharConverter typeconverter, Object value) { if (typeconverter == null) { throw new ArgumentNullException("typeconverter"); } return((T)typeconverter.ConvertTo(value, typeof(T))); }
public void ConvertFromStringTest() { var converter = new CharConverter(); Assert.Equal('a', converter.ConvertFromString("a")); Assert.Equal('a', converter.ConvertFromString(" a ")); Assert.Throws <NotSupportedException>(() => converter.ConvertFromString(null)); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// charconverter.ConvertTo<int>(context, culture, value); /// </example> /// </summary> public static T ConvertTo <T>(this CharConverter charconverter, ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value) { if (charconverter == null) { throw new ArgumentNullException("charconverter"); } return((T)charconverter.ConvertTo(context, culture, value, typeof(T))); }
public void Dispose() { if (output != null) { output.Dispose(); } encoding = null; converter = null; }
public void Dispose() { if (!isClosed) { Close(); } writer = null; converter = null; }
public void CanSerializeAndDeserialize() { char value = char.MaxValue; CharConverter converter = new CharConverter(); byte[] bytes = converter.Serialize(value); char valueFromBytes = converter.Deserialize(bytes); Assert.Equal(valueFromBytes, value); }
public void ConvertToStringTest() { var converter = new CharConverter(); Assert.AreEqual("a", converter.ConvertToString(CultureInfo.CurrentCulture, 'a')); Assert.AreEqual("True", converter.ConvertToString(CultureInfo.CurrentCulture, true)); Assert.AreEqual("", converter.ConvertToString(CultureInfo.CurrentCulture, null)); }
public void ConvertToStringTest() { var converter = new CharConverter(); Assert.Equal("a", converter.ConvertToString('a')); Assert.Equal("True", converter.ConvertToString(true)); Assert.Equal("", converter.ConvertToString(null)); }
public void Dispose() { if (input != null) { input.Dispose(); input = null; } record = null; converterAnsel = null; }
public void TargetType() { // Arrange IConverter converter = new CharConverter(); var expectedType = typeof(Char); // Act var actualType = converter.TargetType; // Assert Assert.Equal(expectedType, actualType); }
public void ConvertToStringTest() { var converter = new CharConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; Assert.AreEqual("a", converter.ConvertToString(typeConverterOptions, 'a')); Assert.AreEqual("True", converter.ConvertToString(typeConverterOptions, true)); Assert.AreEqual("", converter.ConvertToString(typeConverterOptions, null)); }
public void Conversion() { // Arrange IConverter converter = new CharConverter(); var value = "c"; var expectedValue = 'c'; // Act var actualValue = converter.Convert(value, converter.TargetType); // Assert Assert.NotNull(actualValue); Assert.IsType <char>(actualValue); Assert.Equal(expectedValue, (Char)actualValue); }
public void ConvertToStringTest() { var converter = new CharConverter(); var propertyMapData = new MemberMapData(null) { TypeConverter = converter, TypeConverterOptions = { CultureInfo = CultureInfo.CurrentCulture } }; Assert.Equal("a", converter.ConvertToString('a', null, propertyMapData)); Assert.Equal("True", converter.ConvertToString(true, null, propertyMapData)); Assert.Equal("", converter.ConvertToString(null, null, propertyMapData)); }
public void ConvertFromStringTest() { var converter = new CharConverter(); var propertyMapData = new MemberMapData(null); propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture; var row = new CsvReader(new ParserMock()); Assert.Equal('a', converter.ConvertFromString("a", null, propertyMapData)); Assert.Equal('a', converter.ConvertFromString(" a ", null, propertyMapData)); Assert.Equal(' ', converter.ConvertFromString(" ", null, propertyMapData)); Assert.Throws <TypeConverterException>(() => converter.ConvertFromString(null, row, propertyMapData)); }
public void ConvertFromStringTest() { var converter = new CharConverter(); Assert.AreEqual('a', converter.ConvertFromString(CultureInfo.CurrentCulture, "a")); Assert.AreEqual('a', converter.ConvertFromString(CultureInfo.CurrentCulture, " a ")); try { converter.ConvertFromString(CultureInfo.CurrentCulture, null); Assert.Fail(); } catch (CsvTypeConverterException) { } }
public void ConvertFromStringTest() { var converter = new CharConverter(); Assert.AreEqual('a', converter.ConvertFromString("a")); Assert.AreEqual('a', converter.ConvertFromString(" a ")); try { converter.ConvertFromString(null); Assert.Fail(); } catch (NotSupportedException) { } }
/// <summary> /// Gets the char value of a field /// </summary> /// <param name="tag">the FIX tag</param> /// <returns>the char value</returns> /// <exception cref="FieldNotFoundException" /> public char GetChar(int tag) { try { Fields.IField fld = _fields[tag]; if (fld.GetType() == typeof(CharField)) { return(((CharField)fld).Obj); } else { return(CharConverter.Convert(fld.ToString())); } } catch (System.Collections.Generic.KeyNotFoundException) { throw new FieldNotFoundException(tag); } }
public void BadValueConversion() { // Arrange IConverter converter = new CharConverter(); var value = "Hello"; var expectedExceptionMessage = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(char)); var expectedInnerExceptionMessage = "String must be exactly one character long."; // Act using (new LangageSwitcher("en-us")) { var actualException = Assert.Throws <CommandLineParserException>(() => converter.Convert(value, converter.TargetType)); // Assert Assert.Equal(expectedExceptionMessage, actualException.Message); Assert.NotNull(actualException.InnerException); var actualInnerExecption = Assert.IsAssignableFrom <FormatException>(actualException.InnerException); Assert.Equal(expectedInnerExceptionMessage, actualInnerExecption.Message); } }
public void ConvertFromStringTest() { var converter = new CharConverter(); var propertyMapData = new CsvPropertyMapData(null); propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture; Assert.AreEqual('a', converter.ConvertFromString("a", null, propertyMapData)); Assert.AreEqual('a', converter.ConvertFromString(" a ", null, propertyMapData)); Assert.AreEqual(' ', converter.ConvertFromString(" ", null, propertyMapData)); try { converter.ConvertFromString(null, null, propertyMapData); Assert.Fail(); } catch (CsvTypeConverterException) { } }
public void ConvertFromExcelTest() { var converter = new CharConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; Assert.AreEqual('a', converter.ConvertFromExcel(typeConverterOptions, "a")); Assert.AreEqual('a', converter.ConvertFromExcel(typeConverterOptions, " a ")); try { converter.ConvertFromExcel(typeConverterOptions, ""); Assert.Fail(); } catch (ExcelTypeConverterException) { } try { converter.ConvertFromExcel(typeConverterOptions, null); Assert.Fail(); } catch (ExcelTypeConverterException) { } }
public void ConvertFromStringTest() { var converter = new CharConverter(); var propertyMapData = new MemberMapData(null); propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture; var mockRow = new Mock <IReaderRow>(); Assert.AreEqual('a', converter.ConvertFromString("a", null, propertyMapData)); Assert.AreEqual('a', converter.ConvertFromString(" a ", null, propertyMapData)); Assert.AreEqual(' ', converter.ConvertFromString(" ", null, propertyMapData)); try { converter.ConvertFromString(null, mockRow.Object, propertyMapData); Assert.Fail(); } catch (TypeConverterException) { } }
private String GetDataAsString(byte[] bytes) { String dataElement = null; if (encoding.Equals("UTF-8") || encoding.Equals("UTF8")) { try { dataElement = Encoding.UTF8.GetString(bytes); } catch (NotSupportedException e) { throw new MarcException("unsupported encoding", e); } } else if (encoding.Equals("MARC-8") || encoding.Equals("MARC8")) { if (converterAnsel == null) { converterAnsel = new AnselToUnicode(); } dataElement = converterAnsel.Convert(bytes); } else if (encoding.Equals("ISO-8859-1") || encoding.Equals("ISO_8859_1")) { try { dataElement = Encoding.GetEncoding("ISO-8859-1").GetString(bytes); } catch (NotSupportedException e) { throw new MarcException("unsupported encoding", e); } } return(dataElement); }
internal static TypeConverter GetCoreConverterFromCustomType(Type type) { TypeConverter result = null; if (type.IsEnum) { result = new EnumConverter(type); } else if (typeof(int).IsAssignableFrom(type)) { result = new Int32Converter(); } else if (typeof(short).IsAssignableFrom(type)) { result = new Int16Converter(); } else if (typeof(long).IsAssignableFrom(type)) { result = new Int64Converter(); } else if (typeof(uint).IsAssignableFrom(type)) { result = new UInt32Converter(); } else if (typeof(ushort).IsAssignableFrom(type)) { result = new UInt16Converter(); } else if (typeof(ulong).IsAssignableFrom(type)) { result = new UInt64Converter(); } else if (typeof(bool).IsAssignableFrom(type)) { result = new BooleanConverter(); } else if (typeof(double).IsAssignableFrom(type)) { result = new DoubleConverter(); } else if (typeof(float).IsAssignableFrom(type)) { result = new SingleConverter(); } else if (typeof(byte).IsAssignableFrom(type)) { result = new ByteConverter(); } else if (typeof(sbyte).IsAssignableFrom(type)) { result = new SByteConverter(); } else if (typeof(char).IsAssignableFrom(type)) { result = new CharConverter(); } else if (typeof(decimal).IsAssignableFrom(type)) { result = new DecimalConverter(); } else if (typeof(TimeSpan).IsAssignableFrom(type)) { result = new TimeSpanConverter(); } else if (typeof(Guid).IsAssignableFrom(type)) { result = new GuidConverter(); } else if (typeof(string).IsAssignableFrom(type)) { result = new StringConverter(); } else if (typeof(CultureInfo).IsAssignableFrom(type)) { result = new CultureInfoConverter(); } else if (typeof(Type).IsAssignableFrom(type)) { result = new TypeTypeConverter(); } else if (typeof(DateTime).IsAssignableFrom(type)) { result = new DateTimeConverter2(); } return(result); }
public void SetUp() { converter = new CharConverter(); DateTimeFormatInfo info = CultureInfo.CurrentCulture.DateTimeFormat; }