Table of Contents

Class ContentReader

Namespace
Microsoft.Xna.Framework.Content
Assembly
MonoGame.Framework.dll

Defines a worker object that implements most of ContentManger.Load. A new content reader is constructed for each asset loaded.

public sealed class ContentReader : BinaryReader, IDisposable
Inheritance
ContentReader
Implements
Inherited Members
Extension Methods

Properties

AssetName

Gets the name of the asset currently being read by this content reader.

public string AssetName { get; }

Property Value

string

ContentManager

Gets a reference to the ContentManager instance that is using this content reader.

public ContentManager ContentManager { get; }

Property Value

ContentManager

Methods

ReadColor()

Reads a Color from the underlying stream.

public Color ReadColor()

Returns

Color

The Color that was read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadExternalReference<T>()

Reads a relative link to an external file from the underlying stream and returns an asset of type T loaded from the external file.

public T ReadExternalReference<T>()

Returns

T

The asset of type T loaded from the external file at the relative link read from the underlying stream. If the relative link read was null or an empty string, then the default implementation of type T is returned.

Type Parameters

T

The type of asset to expected to be loaded from the external file.

Exceptions

ArgumentNullException

The relative link to the external file read is null or an empty string.

ObjectDisposedException

This was called after the ContentReader.ContentManager was disposed.

-or

The stream is closed.

ContentLoadException

The type of asset in the external file does not match the type specified by T.

-or-

A content file matching the relative link to the external file could not be found.

-or-

The specified path in the relative link to the external file read is invalid (for example, a directory in the path does not exist).

-or-

An error occurred while opening the external file.

EndOfStreamException

The end of stream is reached.

IOException

An I/O error occurred.

ReadMatrix()

Reads a Matrix value from the underlying stream.

public Matrix ReadMatrix()

Returns

Matrix

The Matrix that was read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadObject<T>()

Reads a single managed object from the underlying stream as an instance of the specified type. Can be called recursively.

public T ReadObject<T>()

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

FormatException

The stream is corrupted.

ContentLoadException

Type reader index read from stream is out of bounds

ReadObject<T>(ContentTypeReader)

Reads a single managed object from the underlying stream as an instance of the specified type. Can be called recursively.

public T ReadObject<T>(ContentTypeReader typeReader)

Parameters

typeReader ContentTypeReader

The ContentTypeReader to use to read the object.

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

FormatException

The stream is corrupted.

ContentLoadException

Type reader index read from stream is out of bounds

ReadObject<T>(ContentTypeReader, T)

Reads a single managed object from the underlying stream as an instance of the specified type. Can be called recursively.

public T ReadObject<T>(ContentTypeReader typeReader, T existingInstance)

Parameters

typeReader ContentTypeReader

The ContentTypeReader to use to read the object.

existingInstance T

An existing object to write into.

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

FormatException

The stream is corrupted.

ContentLoadException

Type reader index read from stream is out of bounds

ReadObject<T>(T)

Reads a single managed object from the underlying stream as an instance of the specified type. Can be called recursively.

public T ReadObject<T>(T existingInstance)

Parameters

existingInstance T

An existing object to write into.

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

FormatException

The stream is corrupted.

ContentLoadException

Type reader index read from stream is out of bounds

ReadQuaternion()

Reads a Quaternion from the underlying stream.

public Quaternion ReadQuaternion()

Returns

Quaternion

The Quaternion that was read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadRawObject<T>()

Reads a single managed object from the current stream as an instance of the specified type. If you specify a base class of the actual object type, this method reads data only from the base type.

public T ReadRawObject<T>()

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadRawObject<T>(ContentTypeReader)

Reads a single managed object from the current stream as an instance of the specified type. If you specify a base class of the actual object type, this method reads data only from the base type.

public T ReadRawObject<T>(ContentTypeReader typeReader)

Parameters

typeReader ContentTypeReader

The ContentTypeReader to use to read the object.

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadRawObject<T>(ContentTypeReader, T)

Reads a single managed object from the current stream as an instance of the specified type. If you specify a base class of the actual object type, this method reads data only from the base type.

public T ReadRawObject<T>(ContentTypeReader typeReader, T existingInstance)

Parameters

typeReader ContentTypeReader

The ContentTypeReader to use to read the object.

existingInstance T

An existing object to write into.

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadRawObject<T>(T)

Reads a single managed object from the current stream as an instance of the specified type. If you specify a base class of the actual object type, this method reads data only from the base type.

public T ReadRawObject<T>(T existingInstance)

Parameters

existingInstance T

An existing object to write into.

Returns

T

The object that was read.

Type Parameters

T

The type of object to read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadSharedResource<T>(Action<T>)

Reads a shared resource ID and records it for subsequent fix-up.

public void ReadSharedResource<T>(Action<T> fixup)

Parameters

fixup Action<T>

The fix-up action to perform.

Type Parameters

T

The type of the shared resource.

Exceptions

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

FormatException

The stream is corrupted.

ContentLoadException

The type of the shared resource read does not match the specified T type.

ReadVector2()

Reads a Vector2 from the underlying stream.

public Vector2 ReadVector2()

Returns

Vector2

The Vector2 that was read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadVector3()

Reads a Vector3 from the underlying stream.

public Vector3 ReadVector3()

Returns

Vector3

The Vector3 that was read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.

ReadVector4()

Reads a Vector4 from the underlying stream.

public Vector4 ReadVector4()

Returns

Vector4

The Vector4 that was read.

Exceptions

EndOfStreamException

The end of stream is reached.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurred.