Example #1
0
        Type TryResolveType(string name)
        {
            Type resolved;

            if (name.IndexOf(',') >= 0)
            {
                // It must be an assembly qualified name.
                // Weaken its name and try to load it.
                // If it fails and the name does not end with "Configuration" tries it.
                string fullTypeName, assemblyFullName, assemblyName, versionCultureAndPublicKeyToken;
                if (SimpleTypeFinder.SplitAssemblyQualifiedName(name, out fullTypeName, out assemblyFullName) &&
                    SimpleTypeFinder.SplitAssemblyFullName(assemblyFullName, out assemblyName, out versionCultureAndPublicKeyToken))
                {
                    var weakTypeName = fullTypeName + ", " + assemblyName;
                    resolved = SimpleTypeFinder.RawGetType(weakTypeName, false);
                    if (resolved != null)
                    {
                        return(IsHandlerConfiguration(resolved));
                    }
                    if (!fullTypeName.EndsWith("Configuration"))
                    {
                        weakTypeName = fullTypeName + "Configuration, " + assemblyName;
                        resolved     = SimpleTypeFinder.RawGetType(weakTypeName, false);
                        if (resolved != null)
                        {
                            return(IsHandlerConfiguration(resolved));
                        }
                    }
                }
                return(null);
            }
            // This is a simple type name: try to find the type name in already loaded assemblies.
            var configTypes = AppDomain.CurrentDomain.GetAssemblies()
                              .SelectMany(a => a.GetTypes())
                              .Where(t => typeof(IHandlerConfiguration).IsAssignableFrom(t))
                              .ToList();
            var nameWithC = !name.EndsWith("Configuration") ? name + "Configuration" : null;

            if (name.IndexOf('.') > 0)
            {
                // It is a FullName.
                resolved = configTypes.FirstOrDefault(t => t.FullName == name ||
                                                      (nameWithC != null && t.FullName == nameWithC));
            }
            else
            {
                // There is no dot in the name.
                resolved = configTypes.FirstOrDefault(t => t.Name == name ||
                                                      (nameWithC != null && t.Name == nameWithC));
            }
            return(resolved);
        }
Example #2
0
        PluginAssemblyInfo FindAssembly(string assemblyFullName)
        {
            string assemblyName, versionCultureAndPublicKeyToken;

            if (SimpleTypeFinder.SplitAssemblyFullName(assemblyFullName, out assemblyName, out versionCultureAndPublicKeyToken))
            {
                foreach (var a in _allAssemblies)
                {
                    if (a.AssemblyName.Name == assemblyName)
                    {
                        return(a);
                    }
                }
            }
            return(null);
        }