Table of Contents

Class ContentWriter

Namespace
Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler
Assembly
MonoGame.Framework.Content.Pipeline.dll

Provides an implementation for many of the ContentCompiler methods including compilation, state tracking for shared resources and creation of the header type manifest.

public sealed class ContentWriter : BinaryWriter, IAsyncDisposable, IDisposable
Inheritance
ContentWriter
Implements
Inherited Members

Remarks

A new ContentWriter is constructed for each compilation operation.

Properties

TargetPlatform

Gets the content build target platform.

public TargetPlatform TargetPlatform { get; }

Property Value

TargetPlatform

TargetProfile

Gets or sets the target graphics profile.

public GraphicsProfile TargetProfile { get; }

Property Value

GraphicsProfile

Methods

Dispose(bool)

Releases the resources used by the IDisposable class.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Flush()

All content has been written, so now finalize the header, footer and anything else that needs finalizing.

public override void Flush()

Write(Color)

Writes a Color value.

public void Write(Color value)

Parameters

value Color

Value of a color using Red, Green, Blue, and Alpha values to write.

Write(Matrix)

Writes a Matrix value.

public void Write(Matrix value)

Parameters

value Matrix

Value to write.

Write(Quaternion)

Writes a Matrix value.

public void Write(Quaternion value)

Parameters

value Quaternion

Value to write.

Write(Vector2)

Writes a Vector2 value.

public void Write(Vector2 value)

Parameters

value Vector2

Value to write.

Write(Vector3)

Writes a Vector3 value.

public void Write(Vector3 value)

Parameters

value Vector3

Value to write.

Write(Vector4)

Writes a Vector4 value.

public void Write(Vector4 value)

Parameters

value Vector4

Value to write.

WriteExternalReference<T>(ExternalReference<T>)

Writes the name of an external file to the output binary.

public void WriteExternalReference<T>(ExternalReference<T> reference)

Parameters

reference ExternalReference<T>

External reference to a data file for the content item.

Type Parameters

T

The type of reference.

WriteObject<T>(T)

Writes a single object preceded by a type identifier to the output binary.

public void WriteObject<T>(T value)

Parameters

value T

The value to write.

Type Parameters

T

The type of value.

Remarks

This method can be called recursively with a null value.

WriteObject<T>(T, ContentTypeWriter)

Writes a single object to the output binary, using the specified type hint and writer worker.

public void WriteObject<T>(T value, ContentTypeWriter typeWriter)

Parameters

value T

The value to write.

typeWriter ContentTypeWriter

The content type writer.

Type Parameters

T

The type of value.

Remarks

The type hint should be retrieved from the Initialize method of the ContentTypeWriter that is calling WriteObject, by calling GetTypeWriter and passing it the type of the field used to hold the value being serialized.

WriteRawObject<T>(T)

Writes a single object to the output binary as an instance of the specified type.

public void WriteRawObject<T>(T value)

Parameters

value T

The value to write.

Type Parameters

T

The type of value.

Remarks

If you specify a base class of the actual object value only data from this base type will be written. This method does not write any type identifier so it cannot support null or polymorphic values, and the reader must specify an identical type while loading the compiled data.

WriteRawObject<T>(T, ContentTypeWriter)

Writes a single object to the output binary using the specified writer worker.

public void WriteRawObject<T>(T value, ContentTypeWriter typeWriter)

Parameters

value T

The value to write.

typeWriter ContentTypeWriter

The writer worker. This should be looked up from the Initialize method of the ContentTypeWriter that is calling WriteRawObject, by calling GetTypeWriter.

Type Parameters

T

The type of value.

Remarks

WriteRawObject does not write any type identifier, so it cannot support null or polymorphic values, and the reader must specify an identical type while loading the compiled data.

WriteSharedResource<T>(T)

Adds a shared reference to the output binary and records the object to be serialized later.

public void WriteSharedResource<T>(T value)

Parameters

value T

The object to record.

Type Parameters

T

The type of value.