public Type GetReflectedType(string modelType, bool lookInDependencies) { if (string.IsNullOrEmpty(modelType)) { throw new ArgumentNullException(nameof(modelType)); } if (_compilationResult == null || !_compilationResult.Success) { // If the compilation was not successful, just return null. return(null); } Type modelReflectedType = null; try { modelReflectedType = _compilationResult.Assembly?.GetType(modelType); } catch (Exception ex) { _logger.LogMessage(ex.Message, LogMessageLevel.Error); } if (modelReflectedType == null && lookInDependencies) { // Need to look in the dependencies of this project now. var dependencies = _projectContext.CompilationAssemblies.GetEnumerator(); while (modelReflectedType == null && dependencies.MoveNext()) { try { // Since we are running in the project's dependency context, loading assemblies // by name just works. var dAssemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(dependencies.Current.ResolvedPath)); var dAssembly = _loader.LoadFromName(dAssemblyName); modelReflectedType = dAssembly.GetType(modelType); } catch (Exception ex) { // This is a best effort approach. If we cannot load an assembly for any reason, // just ignore it and look for the type in the next one. _logger.LogMessage(ex.Message, LogMessageLevel.Trace); continue; } } } return(modelReflectedType); }
private AssemblyAttributeGenerator GetAssemblyAttributeGenerator() { var originalAssembly = _loader.LoadFromName( new AssemblyName( Path.GetFileNameWithoutExtension(_projectContext.AssemblyName))); return(new AssemblyAttributeGenerator(originalAssembly)); }