Loads an assembly by given assembly name. - CSharp System.Reflection

CSharp examples for System.Reflection:Assembly

Description

Loads an assembly by given assembly name.

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*from   www. j  a  v  a  2s.  c  om*/

public class Main{
        /// <summary>
        /// Loads an assembly by given assembly name.
        /// </summary>
        /// <param name="assemblyName">The assembly name.</param>
        /// <returns>The loaded assembly.</returns>
        public static Assembly LoadAssembly(this string assemblyName)
        {
            if (assemblyName.IsNullOrWhiteSpace())
            {
                throw new ArgumentException("The assembly name cannot be null, empty or white-space.", nameof(assemblyName));
            }

            var assembly = Assembly.Load(new AssemblyName(assemblyName));

            return assembly;
        }
}

Related Tutorials