|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AssemblyHelper.cs" company="Catel development team">
// Copyright (c) 2008 - 2011 Catel development team. All rights reserved.
// </copyright>
// <summary>
// Assembly helper class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Reflection;
#if SILVERLIGHT
using System.Windows;
using System.Windows.Resources;
#endif
namespace Catel
{
/// <summary>
/// Assembly helper class.
/// </summary>
public static class AssemblyHelper
{
/// <summary>
/// Gets the loaded assemblies by using the right method. For Windows applications, it uses
/// <see cref="AppDomain.GetAssemblies()"/>. For Silverlight, it uses the assemblies
/// from the current application.
/// </summary>
/// <returns>
/// <see cref="List{Assembly}"/> of all loaded assemblies.
/// </returns>
public static List<Assembly> GetLoadedAssemblies()
{
#if SILVERLIGHT
return GetLoadedAssemblies(AppDomain.CurrentDomain);
#else
return GetLoadedAssemblies(AppDomain.CurrentDomain);
#endif
}
/// <summary>
/// Gets the loaded assemblies by using the right method. For Windows applications, it uses
/// <see cref="AppDomain.GetAssemblies()"/>. For Silverlight, it uses the assemblies
/// from the current application.
/// </summary>
/// <param name="appDomain">The app domain to search in.</param>
/// <returns>
/// <see cref="List{Assembly}"/> of all loaded assemblies.
/// </returns>
public static List<Assembly> GetLoadedAssemblies(AppDomain appDomain)
{
#if SILVERLIGHT
List<Assembly> assemblies = new List<Assembly>();
foreach (AssemblyPart assemblyPart in Deployment.Current.Parts)
{
StreamResourceInfo sri = Application.GetResourceStream(new Uri(assemblyPart.Source, UriKind.Relative));
assemblies.Add(new AssemblyPart().Load(sri.Stream));
}
return assemblies;
#else
return new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
#endif
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.