src/Black.Beard.Ioc/ComponentModel/TypeDiscovery.cs
/// <summary>
/// Resolves the type by specified name.
/// </summary>
/// <param name="targetType">Type of the target.</param>
/// <returns></returns>
/// <exception cref="DllNotFoundException"></exception>
Resolves the type by specified name.
Resolves the type by specified name .
public Type ResolveByName(string targetType)
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            Type typeResult = null;
            try
            {
                typeResult = Type.GetType(targetType);
                if (typeResult == null)
                {
                    var targetype = targetType.Split(',');
                    if (targetype.Length == 1)
                        return null;
                    var assemblyName = targetype[0].Trim();
                    var typeName = targetype[1].Trim();
                    Assembly assembly = null;
                    #region resolve assembly
                    var result = new List<Type>();
                    var assemblies = Assemblies().ToArray();
                    foreach (var item in assemblies)
                    {
                        string name = item.GetName().Name;
                        if (name == assemblyName)
                        {
                            assembly = item;
                            break;
                        }
                    }
                    if (assembly == null)
                        throw new DllNotFoundException(assemblyName);
                    #endregion resolve assembly
                    foreach (Type type in assembly.ExportedTypes)
                    {
                        string ns = type.Namespace + "." + type.Name;
                        if (ns == typeName)
                        {
                            typeResult = type;
                            break;
                        }
                    }
                }
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            }
            return typeResult;
        }
public Type ResolveByName ( string targetType ) { AppDomain . CurrentDomain . AssemblyResolve += CurrentDomain_AssemblyResolve ; Type typeResult = null ; try { typeResult = Type . GetType ( targetType ) ; if ( typeResult == null ) { var targetype = targetType . Split ( ' ' ) ; if ( targetype . Length == 1 ) return null ; var assemblyName = targetype [ 0 ] . Trim ( ) ; var typeName = targetype [ 1 ] . Trim ( ) ; Assembly assembly = null ; region  resolve assembly var result = new List < Type > ( ) ; var assemblies = Assemblies ( ) . ToArray ( ) ; foreach ( var item in assemblies ) { string name = item . GetName ( ) . Name ; if ( name == assemblyName ) { assembly = item ; break ; } } if ( assembly == null ) throw new DllNotFoundException ( assemblyName ) ; endregion  resolve assembly foreach ( Type type in assembly . ExportedTypes ) { string ns = type . Namespace + " " + type . Name ; if ( ns == typeName ) { typeResult = type ; break ; } } } } finally { AppDomain . CurrentDomain . AssemblyResolve -= CurrentDomain_AssemblyResolve ; } return typeResult ; }
Resolves the type by specified name.
Resolves the type by specified name .
None
None
targetType
string
Type of the target.
Type of the target .