コード例 #1
0
        void WriteStreamChar(this Stream stream, int offset, char value, bool little)
        {
#if SAFE_CAST
            byte[] intBytes = new byte[2];

            fixed(byte *bs = intBytes)
            {
                char *c = (char *)bs;

                *c = value;
                if (BitConverter.IsLittleEndian != little)
                {
                    Reverse2(c);
                }
            }

            stream.Position = offset;
            stream.Write(intBytes, 0, intBytes.Length);
#else
            if (BitConverter.IsLittleEndian == little)
            {
                CharField fs = new CharField(value);
                fs.Fill(stream, offset);
            }
            else
            {
                RCharField fs = new RCharField(value);
                fs.Fill(stream, offset);
            }
#endif
        }
コード例 #2
0
        void WriteChar(this byte[] arr, int offset, char value, bool little)
        {
#if SAFE_CAST
            fixed(byte *bs = arr)
            {
                char *target = (char *)(bs + offset);

                (*target) = value;
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse(arr, offset, 2);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                CharField fs = new CharField(value);
                fs.Fill(arr, offset);
            }
            else
            {
                RCharField fs = new RCharField(value);
                fs.Fill(arr, offset);
            }
#endif
        }