当前位置: 首页>>代码示例>>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;未经允许,请勿转载。