Can someone explain usage of parameter ‘exisitng instance’ of this method:
public abstract class ContentTypeReader<T> : ContentTypeReader {
protected internal abstract T Read(ContentReader input, T existingInstance);
}
I’ve several custom content readers in my project but I never use this parameter and it’s always null. I can’t find any info online(MSDN page for this method returns 404).
It’s used to reload resources after a Device lost.
If existingInstance is not null, you must reload the asset into existingInstance instead if creating a new one.
public class TileMap {
private Dictionary<int, TileBrush> _tileBrushes;
public Texture2D SpriteSheet { get; }
public ReadOnlyDictionary<int, TileBrush> TileBrushes { get; } // TileBrush is custom content
public TileMap(Texture2D spriteSheet, IEnumerable<TileBrush> tileBrushes) {
this._tileBrushes = tileBrushes.ToDictionary(x => x.Id);
this.TileBrushes = new ReadOnlyDictionary<int, TileBrush>(this._tileBrushes);
}
}
So in case you described(Device lost) I have to load SpriteSheet and TileBrushes again? This will force public setters for all properties and collection type change.