当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadDecimal方法代码示例

本文整理汇总了C#中System.IO.BinaryReader.ReadDecimal方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadDecimal方法的具体用法?C# BinaryReader.ReadDecimal怎么用?C# BinaryReader.ReadDecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadDecimal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

 public override object Read(BinaryReader buffer, Type resultType, TypeDescription typeDescriptor, byte code, BinaryJSONReader binaryJsonReader)
 {
     switch (code)
     {
         case BinaryValue.BYTE:
             return Convert.ChangeType(buffer.ReadByte(), resultType);
         case BinaryValue.SBYTE:
             return Convert.ChangeType(buffer.ReadSByte(), resultType);
         case BinaryValue.INT16:
             return Convert.ChangeType(buffer.ReadInt16(), resultType);
         case BinaryValue.UINT16:
             return Convert.ChangeType(buffer.ReadUInt16(), resultType);
         case BinaryValue.INT32:
             return Convert.ChangeType(buffer.ReadInt32(), resultType);
         case BinaryValue.UINT32:
             return Convert.ChangeType(buffer.ReadUInt32(), resultType);
         case BinaryValue.INT64:
             return Convert.ChangeType(buffer.ReadInt64(), resultType);
         case BinaryValue.UINT64:
             return Convert.ChangeType(buffer.ReadUInt64(), resultType);
         case BinaryValue.FLOAT:
             return Convert.ChangeType(buffer.ReadSingle(), resultType);
         case BinaryValue.BOOLEAN:
             return Convert.ChangeType(buffer.ReadBoolean(), resultType);
         case BinaryValue.DOUBLE:
             return Convert.ChangeType(buffer.ReadDouble(), resultType);
         case BinaryValue.DECIMAL:
             return Convert.ChangeType(buffer.ReadDecimal(), resultType);
         case BinaryValue.CHAR:
             return Convert.ChangeType(buffer.ReadChar(), resultType);
     }
     return null;
 }
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:33,代码来源:PrimitiveSerialization.cs

示例2: Load

        private static bool Load(BinaryReader reader, out Value value)
        {
            List<KeyValuePair<Value, Value>>	array;
            Value								arrayKey;
            Value								arrayValue;
            int									count;
            ValueContent						type;

            type = (ValueContent)reader.ReadInt32 ();

            switch (type)
            {
                case ValueContent.Boolean:
                    value = reader.ReadBoolean () ? BooleanValue.True : BooleanValue.False;

                    break;

                case ValueContent.Map:
                    count = reader.ReadInt32 ();
                    array = new List<KeyValuePair<Value, Value>> (count);

                    while (count-- > 0)
                    {
                        if (!ValueAccessor.Load (reader, out arrayKey) || !ValueAccessor.Load (reader, out arrayValue))
                        {
                            value = null;

                            return false;
                        }

                        array.Add (new KeyValuePair<Value, Value> (arrayKey, arrayValue));
                    }

                    value = array;

                    break;

                case ValueContent.Number:
                    value = reader.ReadDecimal ();

                    break;

                case ValueContent.String:
                    value = reader.ReadString ();

                    break;

                case ValueContent.Void:
                    value = VoidValue.Instance;

                    break;

                default:
                    value = null;

                    return false;
            }

            return true;
        }
开发者ID:r3c,项目名称:cottle,代码行数:60,代码来源:ValueAccessor.cs

示例3: Main

        public static void Main(string[] args)
        {
            BinaryFile classObject = new BinaryFile();
            try
            {
                using (BinaryWriter writerObject = new BinaryWriter(File.Open("file.bin", FileMode.OpenOrCreate)))
                {
                    writerObject.Write(classObject._number);
                    writerObject.Write(classObject._sentence);
                    writerObject.Write(classObject._decimalNumber);
                }
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }

            try
            {

                using (BinaryReader readerObject = new BinaryReader(File.Open("file.bin", FileMode.OpenOrCreate)))
                {
                    Console.WriteLine(readerObject.ReadInt32());
                    Console.WriteLine(readerObject.ReadString());
                    Console.WriteLine(readerObject.ReadDecimal());

                }
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }

            Console.ReadKey();
        }
开发者ID:mohitsinghb-optimus,项目名称:Dot-Net-Induction,代码行数:35,代码来源:BinaryFile.cs

示例4: FormatAs

        private static string FormatAs(byte[] bytes, params string[] types)
        {
            var formatted = new List<string>();

            using (var reader = new BinaryReader(new MemoryStream(bytes)))
            {
                foreach (var type in types)
                {
                    switch (type.ToLower())
                    {
                        case "int32":
                            formatted.Add(reader.ReadInt32().ToString("0000000000"));
                            break;
                        case "single":
                            formatted.Add(reader.ReadSingle().ToString());
                            break;
                        case "double":
                            formatted.Add(reader.ReadDouble().ToString());
                            break;
                        case "decimal":
                            formatted.Add(reader.ReadDecimal().ToString());
                            break;
                        default:
                            throw new Exception();
                    }
                }
            }

            return String.Join(" ", formatted);
        }
开发者ID:singularity-zero,项目名称:SparkFire,代码行数:30,代码来源:MainWindow.xaml.cs

示例5: ReadPrimitive

        private static object ReadPrimitive(BinaryReader reader, Type type)
        {
            if (type == typeof (byte))
                return reader.ReadByte();
            if (type == typeof (float))
                return reader.ReadSingle();
            if (type == typeof (double))
                return reader.ReadDouble();
            if (type == typeof (decimal))
                return reader.ReadDecimal();
            if (type == typeof (int))
                return reader.ReadInt32();
            if (type == typeof (uint))
                return reader.ReadUInt32();
            if (type == typeof (short))
                return reader.ReadInt16();
            if (type == typeof (ushort))
                return reader.ReadUInt16();
            if (type == typeof (long))
                return reader.ReadInt64();
            if (type == typeof (ulong))
                return reader.ReadUInt64();
            if (type == typeof (bool))
                return reader.ReadBoolean();
            if (type == typeof (string))
                return reader.ReadString();
            if (type == typeof (char))
                return reader.ReadChar();
            if (type == typeof (Guid))
                return new Guid(reader.ReadBytes(16));
            if (type == typeof (DateTime))
                return new DateTime(reader.ReadInt64());

            throw new ArgumentException($"Failed to read '{type.FullName}', type not supported", nameof(type));
        }
开发者ID:rioter00,项目名称:Project-Ethos,代码行数:35,代码来源:BinarySerializer.cs

示例6: ValidateDisposedExceptions

        private void ValidateDisposedExceptions(BinaryReader binaryReader)
        {
            byte[] byteBuffer = new byte[10];
            char[] charBuffer = new char[10];

            Assert.Throws<ObjectDisposedException>(() => binaryReader.PeekChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(byteBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(charBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBoolean());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBytes(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChars(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDecimal());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDouble());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt64());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSingle());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadString());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt64());
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:26,代码来源:BinaryReaderTests.cs

示例7: GetProducts

		public static List<Product> GetProducts()
		{
			// if the directory doesn't exist, create it
			if (!Directory.Exists(dir))
				Directory.CreateDirectory(dir);

			// create the object for the input stream for a binary file
			BinaryReader binaryIn = 
				new BinaryReader(
				new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

			// create the array list
			List<Product> products = new List<Product>();

			// read the data from the file and store it in the List<Product>
			while (binaryIn.PeekChar() != -1)
			{
				Product product = new Product();
				product.Code = binaryIn.ReadString();
				product.Description = binaryIn.ReadString();
				product.Price = binaryIn.ReadDecimal();
				products.Add(product);
			}

			// close the input stream for the binary file
			binaryIn.Close();

			return products;
		}
开发者ID:Garry190,项目名称:CSharp,代码行数:29,代码来源:ProductDB.cs

示例8: DeserializeDecimal

 protected virtual Decimal DeserializeDecimal(ArraySegment<byte> value)
 {
     using (var stream = new MemoryStream(value.Array, value.Offset, value.Count)) {
           using (var binaryReader = new BinaryReader(stream)) {
               return binaryReader.ReadDecimal();
           }
       }
 }
开发者ID:kevinayers,项目名称:AL-Redis,代码行数:8,代码来源:ClrBinarySerializer.cs

示例9: ReadBinaryCompleteSignature

        // very manual writer... but want to see how small I can get the data.
        public static CompleteSignature ReadBinaryCompleteSignature(Stream s)
        {
            var sig = new CompleteSignature();

            var l = new List<BlockSignature>();

            var reader = new BinaryReader(s);

            int numberOfEntries = reader.ReadInt32();

            for (var i = 0; i < numberOfEntries; i++)
            {
                var entry = new BlockSignature();

                // 8 bytes. offset
                long offset = reader.ReadInt64();

                // 4 bytes. size
                int size = reader.ReadInt32();

                // 4 bytes. Block Number;
                int blockNumber = reader.ReadInt32();

                // 4 bytes. Rolling Signature.
                decimal sig1 = reader.ReadDecimal();
                decimal sig2 = reader.ReadDecimal();
                RollingSignature rollingSig = new RollingSignature() { Sig1 = sig1, Sig2 = sig2 };

                // should be 16 bytes.
                byte[] md5 = reader.ReadBytes(16);

                entry.BlockNumber = (UInt32)blockNumber;
                entry.RollingSig = (RollingSignature)rollingSig;
                entry.MD5Signature = md5;
                entry.Offset = offset;
                entry.Size = (uint)size;

                l.Add(entry);
            }
            sig.SignatureList = l.ToArray<BlockSignature>();
            return sig;
        }
开发者ID:kpfaulkner,项目名称:BlobSync,代码行数:43,代码来源:SerializationHelper.cs

示例10: GetDecimalValue

        public static decimal GetDecimalValue(this DatasourceRecord record)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.Decimal);

            using (var memoryStream = new MemoryStream(record.Value))
            {
                using (var binaryReader = new BinaryReader(memoryStream))
                {
                    return binaryReader.ReadDecimal();
                }
            }
        }
开发者ID:ytechie,项目名称:time-series-data-azure-guidance,代码行数:12,代码来源:DatasourceRecordExtensions.cs

示例11: BytesToDecimal

 public static decimal BytesToDecimal(byte[] buffer)
 {
     //if (buffer.Length == 1) return Decimal.Parse(((char)buffer[0]).ToString());
     if (buffer.Length == 2) {
         if (buffer[1] == 1) return decimal.MinValue;
         else return decimal.MaxValue;
     }
     using (var ms = new MemoryStream(buffer)) {
         using (var br = new BinaryReader(ms)) {
             return br.ReadDecimal(); ;
         }
     }
 }
开发者ID:blooop,项目名称:MessageShark,代码行数:13,代码来源:CustomBinary.Deserializer.cs

示例12: RetrieveAndDisplayData

        public static void RetrieveAndDisplayData(BinaryReader binReader)
        {
            // Read string data from the file
            Console.WriteLine(binReader.ReadString());

            // Read integer data from the file
            for (int i = 0; i < 11; i++)
            {
                Console.WriteLine(binReader.ReadInt32());
            }

            // Read decimal data from the file
            Console.WriteLine(binReader.ReadDecimal());
        }
开发者ID:moeen-aqrabawi,项目名称:C-.NET,代码行数:14,代码来源:BinaryInput.cs

示例13: BytesToDecimal

        /// <summary>
        /// Byte array to Decimal
        /// </summary>
        /// <param name="src">byte array</param>
        /// <returns>decimal</returns>
        public static Decimal BytesToDecimal(byte[] src)
        {
            if (src.Length == 1)
            {
                return Decimal.Parse(((char)src[0]).ToString());
            }

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream(src))
            {
                using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream))
                {
                    return reader.ReadDecimal();
                }

            }
        }
开发者ID:NotYours180,项目名称:DBreeze,代码行数:21,代码来源:MainWindow.xaml.cs

示例14: WriteDecimal

        public void WriteDecimal()
        {
            MemoryStream stream = new MemoryStream();
            OutputChannel channel = new OutputChannel(new BinaryWriter(stream));

            decimal dc = 12.34m;

            channel.Write(dc);

            stream.Seek(0, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream);

            Assert.AreEqual((byte)Types.Decimal, reader.ReadByte());
            Assert.AreEqual(dc, reader.ReadDecimal());
            Assert.AreEqual(-1, reader.PeekChar());

            reader.Close();
        }
开发者ID:ajlopez,项目名称:ErlSharp,代码行数:19,代码来源:OutputChannelTests.cs

示例15: ByteArrayToDecimal

 public static decimal ByteArrayToDecimal(byte[] src)
 {
     decimal num3;
     if (src.Length < 0x10)
     {
         byte[] buffer = new byte[0x10];
         int num = 0;
         foreach (byte num2 in src)
         {
             buffer[num++] = num2;
         }
         src = buffer;
     }
     using (MemoryStream stream = new MemoryStream(src))
     {
         using (BinaryReader reader = new BinaryReader(stream))
         {
             num3 = reader.ReadDecimal();
         }
     }
     return num3;
 }
开发者ID:samadm,项目名称:ReportGenerator,代码行数:22,代码来源:StreamHelper.cs


注:本文中的System.IO.BinaryReader.ReadDecimal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。