ContentManager.ReadAsset Generic Method
Low-level worker method that reads asset data.
Syntax
'Declaration
Protected Function ReadAsset(Of T) ( _
assetName As String, _
recordDisposableObject As Action(Of IDisposable) _
) As T
protected T ReadAsset<T> (
string assetName,
Action<IDisposable> recordDisposableObject
)
protected:
generic<typename T>
T ReadAsset(
String assetName,
Action<IDisposable> recordDisposableObject
)
Type Parameters
- T
Type of the asset specified for loading.
Parameters
- assetName
Type: String
The name of the asset to be loaded from disk. - recordDisposableObject
Type: Action<IDisposable>
Delegate function for handling the disposition of assets. If recordDisposableObject is null, the default lifespan tracking and management is used, so unloading or disposing of the content manager frees everything that has been loaded through it. If recordDisposableObject specifies a valid delegate, that delegate is used instead of the default lifespan tracking and is called every time the loader encounters a type that implements IDisposable. You must use your own code to unload assets loaded in this fashion, since ContentManager's Unload method will not be aware of them.
Return Value
Type: T
Returns the loaded asset.
Exceptions
Exception type | Condition |
---|---|
ObjectDisposedException | ReadAsset was called after the ContentManager was disposed. |
ArgumentNullException | The assetName argument is null. |
Remarks
This protected method loads an .xnb file from disk. Unlike ContentManager's public Load method, it always returns a new copy of the specified asset, even if the asset has been loaded previously.
You can customize how shared assets are managed by overriding ContentManager's Load method. In your own Load
method, keep track of what has been loaded, and call ReadAsset when you need a new asset from disk.
Requirements
Namespace: Microsoft.Xna.Framework.Content
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)
See Also
Reference
ContentManager Class
ContentManager Members
Microsoft.Xna.Framework.Content Namespace
Platforms
Windows Phone