Exemple #1
0
        private void loadPreferenceFromInput()
        {
            String checkedVal   = new Int32Converter().ConvertToString(1);
            String uncheckedVal = new Int32Converter().ConvertToString(0);

            if (this.keyUseRandom.Checked)
            {
                Preference.Set("compose.randomKeyEnable", checkedVal);
                Preference.Set("compose.minorKeyEnable", (this.minorKeyEnable.Checked) ? checkedVal : uncheckedVal);
                Preference.Set("compose.sharpedKeyEnable", (this.sharpKeyEnable.Checked) ? checkedVal : uncheckedVal);
            }
            else if (this.keyUseFixed.Checked)
            {
                Key keyTest = Key.CreateKeyFromString(fixedKeyDegree.Text);

                Preference.Set("compose.randomKeyEnable", uncheckedVal);
                Preference.Set("compose.keyDegree", keyTest.Degree.ToString());
                Preference.Set("compose.minorKeyFlag", keyTest.MinorFlag ? "1" : "0");
            }
            Preference.Set("compose.substituteChordEnable", (this.substituteEnable.Checked) ? checkedVal : uncheckedVal);
            Preference.Set("compose.barCount", this.barCount.Text);

            Preference.Set("dominant_filter.frequency", dominantFilterFreq.Text);
            Preference.Set("base_line_filter.frequency", baseLineFilterFreq.Text);
            //baseLineFilterFreq
            Preference.Set("compose.barCount", this.barCount.Text);
        }
Exemple #2
0
        /// <summary>
        /// Execute mapping for baseic types
        /// </summary>
        public void MapTypes()
        {
            var wkbConverter     = new WellKnownBinaryConverter(this._geometryFactory);
            var genericConverter = new GenericConverter();
            var int32Converter   = new Int32Converter();

            var map = new TypeMap(DbType.Int32, typeof(uint), genericConverter);

            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Int32, typeof(int), int32Converter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.String, typeof(string), genericConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.DateTime, typeof(DateTime), genericConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IMapPoint), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(ILineString), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IPolygon), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IGeometry), wkbConverter);
            this._typeRegister.Set(map);
        }
Exemple #3
0
        /// <summary>Converts the specified object to the converter's native type.</summary>
        /// <param name="context">A <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that can be used to get additional information about the environment this converter is being called from. This may be <see langword="null" />, so you should always check. Also, properties on the context object may also return <see langword="null" />. </param>
        /// <param name="culture">An <see cref="T:System.Globalization.CultureInfo" /> object that contains culture specific information, such as the language, calendar, and cultural conventions associated with a specific culture. It is based on the RFC 1766 standard. </param>
        /// <param name="value">The object to convert. </param>
        /// <returns>The converted object. </returns>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be completed.</exception>
        // Token: 0x060007B0 RID: 1968 RVA: 0x00011D70 File Offset: 0x0000FF70
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }
            string text = value as string;

            if (text == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }
            string[]       array          = text.Split(culture.TextInfo.ListSeparator.ToCharArray());
            Int32Converter int32Converter = new Int32Converter();

            int[] array2 = new int[array.Length];
            for (int i = 0; i < array2.Length; i++)
            {
                array2[i] = (int)int32Converter.ConvertFromString(context, culture, array[i]);
            }
            if (array.Length != 2)
            {
                throw new ArgumentException("Failed to parse Text(" + text + ") expected text in the format \"Width,Height.\"");
            }
            return(new Size(array2[0], array2[1]));
        }
Exemple #4
0
        public void PropertiesTest()
        {
            var converter = new Int32Converter();

            Assert.AreEqual(true, converter.AcceptsNativeType);
            Assert.AreEqual(typeof(int), converter.ConvertedType);
        }
Exemple #5
0
        /// <summary>将某种格式的密文转为加密后的二进制数据</summary>
        /// <param name="ciphertext">密文</param>
        /// <param name="format">密文格式</param>
        /// <returns>加密后的二进制数据</returns>
        public static byte[] FromCiphertext(string ciphertext, CiphertextFormat format)
        {
            byte[] result = null;

            if (format == CiphertextFormat.Base64String)
            {
                result = Convert.FromBase64String(ciphertext);
            }
            else if (format == CiphertextFormat.HexString)
            {
                string[] data = ciphertext.Split('-');

                result = new byte[data.Length];

                Int32Converter converter = new Int32Converter();

                for (int i = 0; i < data.Length; i++)
                {
                    result[i] = Convert.ToByte(converter.ConvertFromInvariantString(string.Format("0x{0}", data[i])).ToString());
                }
            }
            else if (format == CiphertextFormat.HexStringWhitoutHyphen)
            {
                result = new byte[ciphertext.Length / 2];

                Int32Converter converter = new Int32Converter();

                for (int i = 0; i < ciphertext.Length; i = i + 2)
                {
                    result[i / 2] = Convert.ToByte(converter.ConvertFromInvariantString(string.Format("0x{0}", ciphertext.Substring(i, 2)).ToString()));
                }
            }

            return(result);
        }
 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();
 }
Exemple #7
0
        /// <summary>
        /// Execute mapping for baseic types
        /// </summary>
        public void MapTypes()
        {
            var wkbConverter = new WellKnownBinaryConverter(this._geometryFactory);
            var genericConverter = new GenericConverter();
            var int32Converter = new Int32Converter();

            var map = new TypeMap(DbType.Int32, typeof(uint), genericConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Int32, typeof(int), int32Converter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.String, typeof(string), genericConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.DateTime, typeof(DateTime), genericConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IMapPoint), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(ILineString), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IPolygon), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IGeometry), wkbConverter);
            this._typeRegister.Set(map);
        }
Exemple #8
0
        /// <summary>
        /// Converts the specified value to a <see cref="Padding"/> object
        /// </summary>
        /// <param name="context">Conversion context</param>
        /// <param name="culture">Culture to perform the conversion for</param>
        /// <param name="value">Value to convert</param>
        /// <returns>A new instance of the <see cref="Padding"/> object with the value represented by <paramref name="value"/></returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string text = value as string;

            if (text != null)
            {
                var parts     = text.Split(culture.TextInfo.ListSeparator.ToCharArray());
                var converter = new Int32Converter();
                switch (parts.Length)
                {
                case 1:
                    return(new Padding(
                               (int)converter.ConvertFromString(context, culture, parts[0])
                               ));

                case 2:
                    return(new Padding(
                               (int)converter.ConvertFromString(context, culture, parts[0]),
                               (int)converter.ConvertFromString(context, culture, parts[1])
                               ));

                case 4:
                    return(new Padding(
                               (int)converter.ConvertFromString(context, culture, parts[0]),
                               (int)converter.ConvertFromString(context, culture, parts[1]),
                               (int)converter.ConvertFromString(context, culture, parts[2]),
                               (int)converter.ConvertFromString(context, culture, parts[3])
                               ));

                default:
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot parse value '{0}'. Should be in the form of 'all', 'horizontal,vertical', or 'left, top, right, bottom'", text));
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }
Exemple #9
0
        public override object ConvertFrom(ITypeDescriptorContext context,
                                           CultureInfo culture,
                                           object value)
        {
            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }
            string s = value as string;

            if (s == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }

            string[] subs = s.Split(culture.TextInfo.ListSeparator.ToCharArray());

            Int32Converter converter = new Int32Converter();

            int[] numSubs = new int[subs.Length];
            for (int i = 0; i < numSubs.Length; i++)
            {
                numSubs[i] = (int)converter.ConvertFromString(context, culture, subs[i]);
            }

            if (subs.Length != 2)
            {
                throw new ArgumentException("Failed to parse Text(" + s + ") expected text in the format \"Width,Height.\"");
            }

            return(new Size(numSubs[0], numSubs[1]));
        }
Exemple #10
0
        private void KeepMe()
        {
            var boolConverter   = new BooleanConverter();
            var stringConverter = new StringConverter();
            var enumConverter   = new EnumConverter(null);
            var intConverter    = new Int32Converter();

            var linearLayout = new LinearLayout(null);

            linearLayout.Visibility = ViewStates.Visible;

            var seekBar = new SeekBar(null);

            seekBar.Max      = seekBar.Max;
            seekBar.Progress = seekBar.Progress;

            var textPref = new EditTextPreference(null);

            textPref.Text    = textPref.Text;
            textPref.Enabled = textPref.Enabled;

            var switchPref = new SwitchPreference(null);

            switchPref.Checked = switchPref.Checked;
            switchPref.Enabled = switchPref.Enabled;

            var listPref = new ListPreference(null);

            listPref.Enabled = listPref.Enabled;
            listPref.Value   = listPref.Value;
        }
        public void ShouldThrowExceptionIfDataIndexIsOutOfRange()
        {
            var converter = new Int32Converter();

            var action = new Action(() => converter.ConvertBack(new byte[] { 0x01, 0x02, 0x03 }, 1));

            action.Should().Throw <ArgumentException>();
        }
        public void ShouldReturnDataValueAndNextDataIndex()
        {
            var converter = new Int32Converter();

            var(dataValue, nextDataIndex) = converter.ConvertBack(new byte[] { 0xDD, 0x2A, 0x00, 0x00, 0x00 }, 1);

            dataValue.Should().Be(0x2A);
            nextDataIndex.Should().Be(0x05);
        }
Exemple #13
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>
        /// basenumberconverter.ConvertTo&lt;int&gt;(context, culture, value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this Int32Converter basenumberconverter, ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value)
        {
            if (basenumberconverter == null)
            {
                throw new ArgumentNullException("basenumberconverter");
            }

            return((T)basenumberconverter.ConvertTo(context, culture, value, typeof(T)));
        }
Exemple #14
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 Int32Converter typeconverter, Object value)
        {
            if (typeconverter == null)
            {
                throw new ArgumentNullException("typeconverter");
            }

            return((T)typeconverter.ConvertTo(value, typeof(T)));
        }
Exemple #15
0
        public void TargetType()
        {
            // Arrange
            IConverter converter    = new Int32Converter();
            var        expectedType = typeof(Int32);

            // Act
            var actualType = converter.TargetType;

            // Assert
            Assert.Equal(expectedType, actualType);
        }
        public void ShouldReturnByteArray()
        {
            var       converter = new Int32Converter();
            const int data      = 0x11223344;

            var bytes = converter.Convert(data).ToArray();

            bytes.Should().HaveCount(4);
            bytes[0].Should().Be(0x44);
            bytes[1].Should().Be(0x33);
            bytes[2].Should().Be(0x22);
            bytes[3].Should().Be(0x11);
        }
Exemple #17
0
        private JsonFxAOT()
        {
            TypeConverter c;

            c          = new ArrayConverter();
            m_fakeFlag = c.Equals(c);
            //c = new BaseNumberConverter();
            //m_fakeFlag = c.Equals(c);
            c          = new BooleanConverter();
            m_fakeFlag = c.Equals(c);
            c          = new ByteConverter();
            m_fakeFlag = c.Equals(c);
            c          = new CollectionConverter();
            m_fakeFlag = c.Equals(c);
            c          = new ComponentConverter(typeof(int));
            m_fakeFlag = c.Equals(c);
            c          = new CultureInfoConverter();
            m_fakeFlag = c.Equals(c);
            c          = new DateTimeConverter();
            m_fakeFlag = c.Equals(c);
            c          = new DecimalConverter();
            m_fakeFlag = c.Equals(c);
            c          = new DoubleConverter();
            m_fakeFlag = c.Equals(c);
            c          = new EnumConverter(typeof(int));
            m_fakeFlag = c.Equals(c);
            c          = new ExpandableObjectConverter();
            m_fakeFlag = c.Equals(c);
            c          = new Int16Converter();
            m_fakeFlag = c.Equals(c);
            c          = new Int32Converter();
            m_fakeFlag = c.Equals(c);
            c          = new Int64Converter();
            m_fakeFlag = c.Equals(c);
            c          = new NullableConverter(typeof(object));
            m_fakeFlag = c.Equals(c);
            c          = new SByteConverter();
            m_fakeFlag = c.Equals(c);
            c          = new SingleConverter();
            m_fakeFlag = c.Equals(c);
            c          = new StringConverter();
            m_fakeFlag = c.Equals(c);
            c          = new TimeSpanConverter();
            m_fakeFlag = c.Equals(c);
            c          = new UInt16Converter();
            m_fakeFlag = c.Equals(c);
            c          = new UInt32Converter();
            m_fakeFlag = c.Equals(c);
            c          = new UInt64Converter();
            m_fakeFlag = c.Equals(c);
        }
        public override bool CanConvertTo(object sourceValue, Type destinationType)
        {
            if (sourceValue == null)
            {
                return(false);
            }
            if (destinationType == typeof(int))
            {
                return(true);
            }

            Int32Converter dc = new Int32Converter();

            return(dc.CanConvertTo(destinationType));
        }
        public override bool CanConvertFrom(object sourceValue, Type destinationType)
        {
            if (sourceValue == null)
            {
                return(true);
            }
            if (sourceValue.GetType() == typeof(int))
            {
                return(true);
            }

            Int32Converter dc = new Int32Converter();

            return(dc.CanConvertFrom(sourceValue.GetType()));
        }
Exemple #20
0
        public void Conversion()
        {
            // Arrange
            IConverter converter     = new Int32Converter();
            var        value         = "42";
            var        expectedValue = 42;

            // Act
            var actualValue = converter.Convert(value, converter.TargetType);

            // Assert
            Assert.NotNull(actualValue);
            Assert.IsType <Int32>(actualValue);
            Assert.Equal(expectedValue, (Int32)actualValue);
        }
        public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase)
        {
            if (sourceValue == null)
            {
                return(null);
            }
            if (sourceValue.GetType() == typeof(int))
            {
                return(new OptionSetValue((int)sourceValue));
            }

            Int32Converter dc = new Int32Converter();

            return(new OptionSetValue((int)dc.ConvertFrom(sourceValue)));
        }
        /// <summary>
        /// Tries to parse a 32-bit integer from a string. This method should handle hexadecimal values
        /// as well as normal values.
        /// </summary>
        /// <param name="value">The string value to parse.</param>
        /// <param name="result">The parsed integer, if the string was valid. If invalid, this
        /// will be the default integer value.</param>
        /// <returns>True if the conversion was successful; otherwise returns false.</returns>
        public static bool TryParseEx(string value, out int result)
        {
            bool canConvert = true;

            try
            {
                var converter = new Int32Converter();
                result = (int)converter.ConvertFromString(value);
            }
            catch (Exception)
            {
                result     = default(int);
                canConvert = false;
            }

            return(canConvert);
        }
        private bool TryGetInt(object value, out int intValue)
        {
            if (value is int)
            {
                intValue = (int)value;
                return(true);
            }
            var converter      = new Int32Converter();
            var convertedValue = converter.ConvertFrom(value);

            if (convertedValue != null)
            {
                intValue = (int)convertedValue;
                return(true);
            }
            intValue = 0;
            return(false);
        }
Exemple #24
0
        public void t1()
        {
            // 一次累计流量 1027
            //
            byte[] bs = new byte[]{0x03, 0x04, 0x00, 0x00};
            Int32Converter c = new Int32Converter();
            int i = (int)c.ConvertToObject(bs);

            FloatConverter f = new FloatConverter();
            float fv = (float)f.ConvertToObject(bs);
            fv = (float)Math.Round(fv, 2);

            //Assert.AreEqual(i, fv);

            f.IsLittleEndian = false;
            bs = f.ConvertToBytes(10.01F);
            float f2 = (float)f.ConvertToObject(bs);
            Assert.AreEqual(10.01F, f2);
        }
Exemple #25
0
        /// <summary>
        /// Converts the specified value to a <see cref="Size"/>
        /// </summary>
        /// <param name="context">Conversion context</param>
        /// <param name="culture">Culture to perform the conversion</param>
        /// <param name="value">Value to convert</param>
        /// <returns>A new instance of a <see cref="Size"/> converted from the specified <paramref name="value"/></returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var text = value as string;

            if (text != null)
            {
                var parts = text.Split(culture.TextInfo.ListSeparator.ToCharArray());
                if (parts.Length != 2)
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot parse value '{0}' as size.  Should be in the form of 'width,height'", text));
                }

                var converter = new Int32Converter();
                return(new Size(
                           (int)converter.ConvertFromString(context, culture, parts [0]),
                           (int)converter.ConvertFromString(context, culture, parts [1])
                           ));
            }
            return(base.ConvertFrom(context, culture, value));
        }
Exemple #26
0
        public void v2()
        {
            int n = 0x123456;
            Int32Converter c = new Int32Converter();
            byte[] bs = c.ConvertToBytes(n);
            Console.WriteLine(Xdgk.Common.HexStringConverter.Default.ConvertToObject(bs));
            int m = (Int32)c.ConvertToObject(bs);

            Assert.AreEqual(n,m);
            Assert.IsTrue(c.IsLittleEndian);
            Console.WriteLine( Xdgk.Common.HexStringConverter.Default.ConvertToObject(bs) );

            c.IsLittleEndian = false;
            byte[] bs2 = c.ConvertToBytes(n);
            m = (Int32)c.ConvertToObject(bs2);
            Assert.AreEqual(n,m);

            Assert.AreNotEqual(bs, bs2);
            Console.WriteLine( Xdgk.Common.HexStringConverter.Default.ConvertToObject(bs2) );
        }
Exemple #27
0
        public void BadValueConversion()
        {
            // Arrange
            IConverter converter = new Int32Converter();
            var        value     = "Hello";
            var        expectedExceptionMessage      = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(int));
            var        expectedInnerExceptionMessage = "Input string was not in a correct format.";

            // 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);
            }
        }
Exemple #28
0
        public void ConvertFromExcelTest()
        {
            var converter            = new Int32Converter();
            var typeConverterOptions = new TypeConverterOptions {
                CultureInfo = CultureInfo.CurrentCulture
            };

            Assert.AreEqual(123, converter.ConvertFromExcel(typeConverterOptions, (double)123));
            Assert.AreEqual(123, converter.ConvertFromExcel(typeConverterOptions, "123"));
            Assert.AreEqual(123, converter.ConvertFromExcel(typeConverterOptions, " 123 "));
            Assert.AreEqual(0, converter.ConvertFromExcel(typeConverterOptions, null));

            typeConverterOptions.NumberStyle = NumberStyles.HexNumber;
            Assert.AreEqual(0x123, converter.ConvertFromExcel(typeConverterOptions, "123"));

            try {
                converter.ConvertFromExcel(typeConverterOptions, "");
                Assert.Fail();
            } catch (ExcelTypeConverterException) {
            }
        }
Exemple #29
0
        /// <summary>
        /// DES descrypt.
        /// </summary>
        /// <param name="i_key">Keys</param>
        /// <param name="i_IV">initial vector</param>
        /// <param name="i_data">Data</param>
        /// <returns></returns>
        public static string Decrypt(string i_key, string i_IV, string i_data)
        {
            string[]       m_datas        = i_data.Split('-');
            byte[]         m_values       = new byte[m_datas.Length];
            Int32Converter m_i32Converter = new Int32Converter();

            for (int i = 0; i < m_datas.Length; i++)
            {
                m_values[i] = Convert.ToByte(m_i32Converter.ConvertFromInvariantString("0x" + m_datas[i]).ToString());
            }
            byte[] m_keys = Encoding.ASCII.GetBytes(i_key);
            byte[] m_IVs  = Encoding.ASCII.GetBytes(i_IV);
            byte[] m_data = Encoding.ASCII.GetBytes(i_data);
            DESCryptoServiceProvider m_DES     = new DESCryptoServiceProvider();
            ICryptoTransform         m_decrypt = m_DES.CreateDecryptor(m_keys, m_IVs);

            byte[] m_result = m_decrypt.TransformFinalBlock(m_values, 0, m_values.Length);
            m_decrypt.Dispose();
            m_DES.Clear();
            return(Encoding.ASCII.GetString(m_result));
        }
        public override object ConvertTo(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase)
        {
            if (sourceValue == null)
            {
                throw new NotSupportedException();
            }

            if (sourceValue is OptionSetValue optionsetValue)
            {
                if (destinationType == typeof(int))
                {
                    return(optionsetValue.Value);
                }
                else
                {
                    Int32Converter dc = new Int32Converter();
                    return(dc.ConvertTo(optionsetValue.Value, destinationType));
                }
            }

            return(new NotSupportedException());
        }
Exemple #31
0
        public void t1()
        {
            // 一次累计流量 1027
            //
            byte[]         bs = new byte[] { 0x03, 0x04, 0x00, 0x00 };
            Int32Converter c  = new Int32Converter();
            int            i  = (int)c.ConvertToObject(bs);

            FloatConverter f  = new FloatConverter();
            float          fv = (float)f.ConvertToObject(bs);

            fv = (float)Math.Round(fv, 2);

            //Assert.AreEqual(i, fv);


            f.IsLittleEndian = false;
            bs = f.ConvertToBytes(10.01F);
            float f2 = (float)f.ConvertToObject(bs);

            Assert.AreEqual(10.01F, f2);
        }
        public override void Encode(int obj, PacketData data)
        {
            Int32Converter conv  = obj;
            var            pos   = data.Position;
            var            bytes = data.Data;

            if (BitConverter.IsLittleEndian)
            {
                bytes[pos]     = conv.Byte0;
                bytes[pos + 1] = conv.Byte1;
                bytes[pos + 2] = conv.Byte2;
                bytes[pos + 3] = conv.Byte3;
            }
            else
            {
                bytes[pos + 3] = conv.Byte0;
                bytes[pos + 2] = conv.Byte1;
                bytes[pos + 1] = conv.Byte2;
                bytes[pos]     = conv.Byte3;
            }

            data.ShiftPosition(ByteSize);
        }
Exemple #33
0
        public void v2()
        {
            int            n = 0x123456;
            Int32Converter c = new Int32Converter();

            byte[] bs = c.ConvertToBytes(n);
            Console.WriteLine(Xdgk.Common.HexStringConverter.Default.ConvertToObject(bs));
            int m = (Int32)c.ConvertToObject(bs);

            Assert.AreEqual(n, m);
            Assert.IsTrue(c.IsLittleEndian);
            Console.WriteLine(Xdgk.Common.HexStringConverter.Default.ConvertToObject(bs));


            c.IsLittleEndian = false;
            byte[] bs2 = c.ConvertToBytes(n);
            m = (Int32)c.ConvertToObject(bs2);
            Assert.AreEqual(n, m);


            Assert.AreNotEqual(bs, bs2);
            Console.WriteLine(Xdgk.Common.HexStringConverter.Default.ConvertToObject(bs2));
        }