예제 #1
0
 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();
 }
예제 #2
0
 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;
     }
 }
예제 #3
0
        public void PropertiesTest()
        {
            var converter = new CharConverter();

            Assert.AreEqual(true, converter.AcceptsNativeType);
            Assert.AreEqual(typeof(char), converter.ConvertedType);
        }
예제 #4
0
 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"); });
 }
예제 #5
0
        public void SetUp()
        {
            converter = new CharConverter();

            DateTimeFormatInfo info = CultureInfo.CurrentCulture.DateTimeFormat;

            pattern = info.ShortDatePattern + " " + info.ShortTimePattern;
        }
예제 #6
0
 /// <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;
     }
 }
예제 #7
0
        public void ConvertFromStringTest()
        {
            var converter = new CharConverter();

            Assert.AreEqual('a', converter.ConvertFromString("a"));
            Assert.AreEqual('a', converter.ConvertFromString(" a "));

            converter.ConvertFromString(null);
        }
예제 #8
0
        /// <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&lt;int&gt;(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)));
        }
예제 #9
0
        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));
        }
예제 #10
0
        /// <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&lt;int&gt;(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)));
        }
예제 #11
0
 public void Dispose()
 {
     if (output != null)
     {
         output.Dispose();
     }
     encoding  = null;
     converter = null;
 }
예제 #12
0
 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);
        }
예제 #14
0
        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));
        }
예제 #15
0
        public void ConvertToStringTest()
        {
            var converter = new CharConverter();

            Assert.Equal("a", converter.ConvertToString('a'));

            Assert.Equal("True", converter.ConvertToString(true));

            Assert.Equal("", converter.ConvertToString(null));
        }
예제 #16
0
 public void Dispose()
 {
     if (input != null)
     {
         input.Dispose();
         input = null;
     }
     record         = null;
     converterAnsel = null;
 }
예제 #17
0
        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));
        }
예제 #19
0
        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);
        }
예제 #20
0
        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));
        }
예제 #21
0
        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));
        }
예제 #22
0
        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)
            {
            }
        }
예제 #23
0
        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)
            {
            }
        }
예제 #24
0
 /// <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);
     }
 }
예제 #25
0
        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);
            }
        }
예제 #26
0
        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)
            {
            }
        }
예제 #27
0
        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) {
            }
        }
예제 #28
0
        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)
            {
            }
        }
예제 #29
0
        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);
        }
예제 #30
0
        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);
        }
예제 #31
0
        public void SetUp()
        {
            converter = new CharConverter();

            DateTimeFormatInfo info = CultureInfo.CurrentCulture.DateTimeFormat;
        }