private static Type ResolveTypeByLoadAssembly()

in src/TestFramework/Core/TestToolHelpers.cs [77:125]


        private static Type ResolveTypeByLoadAssembly(string nameOfType, string assemblyLoadDir)
        {
            Type type = null;

            int index = nameOfType.IndexOf(',');
            if (index != -1)
            {
                string typeName = nameOfType.Substring(0, index);
                string adapterAssemblyName = nameOfType.Substring(index + 1).Trim();
                string path = Path.Combine(assemblyLoadDir, adapterAssemblyName + ".dll");
                if (File.Exists(path))
                {
                    try
                    {
                        AssemblyName assemblyName = AssemblyName.GetAssemblyName(path);
                        Assembly adapterAssm = Assembly.Load(assemblyName);
                        type = adapterAssm.GetType(typeName, false);
                    }
                    catch (ArgumentException e)
                    {
                        throw new InvalidOperationException(
                            String.Format(CultureInfo.InvariantCulture, "The specified type {0} could not be resolved.", nameOfType),
                            e);
                    }
                    catch (FileLoadException e)
                    {
                        throw new InvalidOperationException(
                              String.Format(CultureInfo.InvariantCulture, "The specified type {0} could not be resolved.", nameOfType),
                              e);
                    }
                    catch (TypeLoadException e)
                    {
                        throw new InvalidOperationException(
                              String.Format(CultureInfo.InvariantCulture, "The specified type {0} could not be resolved.", nameOfType),
                              e);
                    }
                }
                else
                {
                    //search current working folder only once.
                    if (assemblyLoadDir != Environment.CurrentDirectory)
                    {
                        type = ResolveTypeByLoadAssembly(nameOfType, Environment.CurrentDirectory);
                    }
                }
            }

            return type;
        }