// NAnt - A .NET build tool // Copyright (C) 2001-2004 Gerry Shaw // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // Ian Maclean (imaclean@gmail.com) // Jaroslaw Kowalski (jkowalski@users.sourceforge.net) using System; using System.IO; using System.Collections; using System.Reflection; using System.Globalization; using NAnt.Core; using NAnt.Core.Types; using NAnt.Core.Attributes; namespace NAnt.Core.Functions { /// /// Functions to return information for a given assembly. /// [FunctionSet("assembly", "Assembly")] public class AssemblyFunctions : FunctionSetBase { #region Public Instance Constructors public AssemblyFunctions(Project project, PropertyDictionary properties) : base(project, properties) {} #endregion Public Instance Constructors #region Public Instance Methods /// /// Loads an assembly given its file name or path. /// /// The name or path of the file that contains the manifest of the assembly. /// /// The loaded assembly. /// /// is an empty . /// is not found, or the module you are trying to load does not specify a filename extension. /// is not a valid assembly. /// An assembly or module was loaded twice with two different evidences, or the assembly name is longer than MAX_PATH characters. [Function("load-from-file")] public Assembly LoadFromFile(string assemblyFile) { return Assembly.LoadFrom(Project.GetFullPath(assemblyFile), AppDomain.CurrentDomain.Evidence); } /// /// Loads an assembly given the long form of its name. /// /// The long form of the assembly name. /// /// The loaded assembly. /// /// is a . /// is not found. /// /// /// Determine the location of the Microsoft Access 11 Primary Interop /// Assembly by loading it using its fully qualified name, and copy it /// to the build directory. /// /// /// /// /// ]]> /// /// [Function("load")] public Assembly Load(string assemblyString) { return Assembly.Load(assemblyString, AppDomain.CurrentDomain.Evidence); } #endregion Public Instance Methods #region Public Static Methods /// /// Gets the full name of the assembly, also known as the display name. /// /// The assembly to get the full name for. /// /// The full name of the assembly, also known as the display name. /// [Function("get-full-name")] public static string GetFullName(Assembly assembly) { return assembly.FullName; } /// /// Gets an for the specified assembly. /// /// The assembly to get an for. /// /// An for the specified assembly. /// /// [Function("get-name")] public static AssemblyName GetName(Assembly assembly) { return assembly.GetName(false); } /// /// Gets the physical location, in codebase format, of the loaded file /// that contains the manifest. /// /// The assembly to get the location for. /// /// The location of the specified assembly. /// [Function("get-location")] public static string GetLocation(Assembly assembly) { return assembly.Location; } #endregion Public Static Methods } }