本文整理汇总了C#中IResourceAccessor.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IResourceAccessor.Dispose方法的具体用法?C# IResourceAccessor.Dispose怎么用?C# IResourceAccessor.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResourceAccessor
的用法示例。
在下文中一共展示了IResourceAccessor.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLocalFsResourceAccessor
/// <summary>
/// Returns a resource accessor instance of interface <see cref="ILocalFsResourceAccessor"/>. This instance will return the
/// given <paramref name="baseResourceAccessor"/>, casted to <see cref="ILocalFsResourceAccessor"/> if possible, or
/// a new instance of <see cref="StreamedResourceToLocalFsAccessBridge"/> to provide the <see cref="ILocalFsResourceAccessor"/>
/// instance.
/// </summary>
/// <remarks>
/// The ownership of the given <paramref name="baseResourceAccessor"/> is transferred from the caller to the returned
/// result value. That means, if this method succeeds, the caller must dispose the result value, it must not dispose
/// the given <paramref name="baseResourceAccessor"/> any more.
/// </remarks>
/// <param name="baseResourceAccessor">Resource accessor which is used to provide the resource contents.</param>
/// <param name="path">Relative path based on the given baseResourceAccessor.</param>
/// <returns>Resource accessor which implements <see cref="ILocalFsResourceAccessor"/>.</returns>
public static ILocalFsResourceAccessor GetLocalFsResourceAccessor(IResourceAccessor baseResourceAccessor, string path)
{
// Try to get an ILocalFsResourceAccessor
ILocalFsResourceAccessor result = baseResourceAccessor as ILocalFsResourceAccessor;
if (result != null)
// Simple case: The media item is located in the local file system or the resource provider returns
// an ILocalFsResourceAccessor from elsewhere - simply return it
return result;
// Set up a resource bridge mapping the remote or complex resource to a local file or directory
string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize();
MountingDataProxy md;
bool dispose = false;
lock (_syncObj)
{
if (_activeMounts.TryGetValue(key, out md))
// Base accessor not needed - we use our cached accessor
dispose = true;
else
_activeMounts.Add(key, md = CreateMountingDataProxy(key, baseResourceAccessor));
}
if (dispose)
baseResourceAccessor.Dispose();
return new StreamedResourceToLocalFsAccessBridge(md, path);
}