當前位置: 首頁>>代碼示例>>C#>>正文


C# BinaryWriter.Align方法代碼示例

本文整理匯總了C#中System.IO.BinaryWriter.Align方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryWriter.Align方法的具體用法?C# BinaryWriter.Align怎麽用?C# BinaryWriter.Align使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.BinaryWriter的用法示例。


在下文中一共展示了BinaryWriter.Align方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Write

        /// <summary>
        /// Writes a <see cref="VersionResource"/> object to the current <see cref="Stream"/>.
        /// </summary>
        /// <param name="resource">
        /// The <see cref="VersionResource"/> to write.
        /// </param>
        public void Write(VersionResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            if (Stream.Length < resource.Size)
            {
                Stream.SetLength(resource.Size);
            }

            using (var stream = new SubStream(Stream, 0, Stream.Length, leaveParentOpen: true))
            using (var writer = new BinaryWriter(stream, Encoding.Unicode))
            {
                // Write the version resource header
                WriteHeader(
                    writer,
                    resource.Size,
                    resource.FixedFileInfo == null ? 0 : Marshal.SizeOf(typeof(VS_FIXEDFILEINFO)),
                    VersionDataType.Binary,
                    "VS_VERSION_INFO");

                if (resource.FixedFileInfo != null)
                {
                    writer.WriteStruct(resource.FixedFileInfo.Value);
                }

                writer.Align();

                if (resource.VarFileInfo != null)
                {
                    WriteHeader(writer, resource.VarFileInfoSize, 0, VersionDataType.Text, "VarFileInfo");

                    WriteVarFileInfo(writer, resource);
                }

                if (resource.StringFileInfo != null)
                {
                    WriteHeader(writer, resource.StringFileInfoSize, 0, VersionDataType.Text, "StringFileInfo");

                    WriteStringFileInfo(writer, resource);
                }
            }
        }
開發者ID:Fody,項目名稱:Stamp,代碼行數:51,代碼來源:VersionResourceWriter.cs

示例2: WriteHeader

        private void WriteHeader(BinaryWriter writer, long length, long valueLength, VersionDataType binary, string key)
        {
            var header = new VersionHeader
            {
                Length = (ushort)length,
                ValueLength = (ushort)valueLength,
                Type = binary
            };

            writer.WriteStruct(header);
            writer.WriteUnicodeString(key);
            writer.Align();
        }
開發者ID:Fody,項目名稱:Stamp,代碼行數:13,代碼來源:VersionResourceWriter.cs

示例3: WriteStringFileInfo

        private void WriteStringFileInfo(BinaryWriter writer, VersionResource resource)
        {
            foreach (var value in resource.StringFileInfo)
            {
                var languageIdentifier = value.Language;
                var codePage = (ushort)value.Encoding.CodePage;

                var key = (uint)languageIdentifier << 4 | codePage;

                WriteHeader(writer, value.Size, 0, VersionDataType.Text, key.ToString("x8"));

                foreach (var pair in value.Values)
                {
                    long valueLength = Encoding.Unicode.GetByteCount(pair.Value + '\0');
                    long keyLength = Encoding.Unicode.GetByteCount(pair.Key + '\0');

                    long length = Marshal.SizeOf(typeof(VersionHeader));
                    length += keyLength;
                    length = Helpers.Align(length);
                    length += valueLength;
                    length = Helpers.Align(length);

                    WriteHeader(writer, length, valueLength / sizeof(short), VersionDataType.Text, pair.Key);
                    writer.WriteUnicodeString(pair.Value);
                    writer.Align();
                }
            }
        }
開發者ID:Fody,項目名稱:Stamp,代碼行數:28,代碼來源:VersionResourceWriter.cs

示例4: Assemble

        /// <inheritdoc />
        public override void Assemble(BinaryWriter writer)
        {
            // CONTRACT: ObjectFile

            // TODO: Emit .bss after the last progbits section.

            // Create a new context.
            Context context = this.ObjectFile.Architecture.CreateContext(this.ObjectFile);

            // Construct each section.
            context.Reset();
            context.Address = 0;		// Addresses relative to file.
            foreach (Section section in this.ObjectFile.Sections)
            {
                context.Section = section;
                string sectionName = String.Format("section.{0}.start", section.Identifier);
                var symbol = new Symbol(SymbolType.Private, sectionName);
                symbol.Define(context, context.Address);

                section.Construct(context);
            }

            // Emit each section and write it directly to the writer.
            context.Reset();
            context.Address = 0;		// Addresses relative to file.
            foreach (Section section in this.ObjectFile.Sections)
            {
                MathExt.CalculatePadding(writer.BaseStream.Position, section.Alignment);
                writer.Align(section.Alignment);
                section.Emit(writer, context);
            }

            // Test for illegal symbols.
            CheckSymbolSupport(context);

            writer.Flush();
        }
開發者ID:Konctantin,項目名稱:CSharpAssembler,代碼行數:38,代碼來源:BinObjectFileAssembler.cs


注:本文中的System.IO.BinaryWriter.Align方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。