Nez.Portable/Utils/NezContentManager.cs
/// <summary>
/// removes assetName from LoadedAssets and Disposes of it. Note that this method uses reflection to get at the private ContentManager
/// disposeableAssets List.
/// </summary>
/// <param name="assetName">Asset name.</param>
/// <typeparam name="T">The 1st type parameter.</typeparam>
removes assetName from LoadedAssets and Disposes of it. Note that this method uses reflection to get at the private ContentManager
disposeableAssets List.
removes assetName from LoadedAssets and Disposes of it . Note that this method uses reflection to get at the private ContentManager disposeableAssets List .
public void unloadAsset<T>(string assetName)
            where T : class, IDisposable
        {
            if (isAssetLoaded(assetName))
            {
                try
                {
                    FieldInfo fieldInfo = null;
                    var fields = typeof(ContentManager).GetRuntimeFields();
                    foreach (var field in fields)
                    {
                        if (field.Name == "disposableAssets")
                        {
                            fieldInfo = field;
                            break;
                        }
                    }
#if FNA
					fieldInfo = typeof( ContentManager ).GetRuntimeField( "loadedAssets" );
					var LoadedAssets = fieldInfo.GetValue( this ) as Dictionary<string, object>;
					#endif
                    var assetToRemove = LoadedAssets[assetName];
                    var assets = fieldInfo.GetValue(this) as List<IDisposable>;
                    for (var i = 0; i < assets.Count; i++)
                    {
                        var typedAsset = assets[i] as T;
                        if (typedAsset != null && typedAsset == assetToRemove)
                        {
                            typedAsset.Dispose();
                            assets.RemoveAt(i);
                            break;
                        }
                    }
                    LoadedAssets.Remove(assetName);
                }
                catch (Exception e)
                {
                    Debug.error("Could not unload asset {0}. {1}", assetName, e);
                }
            }
        }
public void unloadAsset < T > ( string assetName ) where T : class , IDisposable { if ( isAssetLoaded ( assetName ) ) { try { FieldInfo fieldInfo = null ; var fields = typeof ( ContentManager ) . GetRuntimeFields ( ) ; foreach ( var field in fields ) { if ( field . Name == " " ) { fieldInfo = field ; break ; } } if FNA fieldInfo = typeof ( ContentManager ) . GetRuntimeField ( " " ) ; var LoadedAssets = fieldInfo . GetValue ( this ) as Dictionary < string , object > ; endif var assetToRemove = LoadedAssets [ assetName ] ; var assets = fieldInfo . GetValue ( this ) as List < IDisposable > ; for ( var i = 0 ; i < assets . Count ; i ++ ) { var typedAsset = assets [ i ] as T ; if ( typedAsset != null && typedAsset == assetToRemove ) { typedAsset . Dispose ( ) ; assets . RemoveAt ( i ) ; break ; } } LoadedAssets . Remove ( assetName ) ; } catch ( Exception e ) { Debug . error ( " " , assetName , e ) ; } } }
removes assetName from LoadedAssets and Disposes of it.
removes assetName from LoadedAssets and Disposes of it .
// first fetch the actual asset. we already know its loaded so we'll grab it directly // see if the asset is disposeable. If so, find and dispose of it.
assetName
string
None
typeparam
The 1st type parameter.
The 1st type parameter .