public void TestGetReflectedType() { using (var fileProvider = new TemporaryFileProvider()) { SetupProjectInformation(fileProvider); var compilation = _workspace.CurrentSolution.Projects .First() .GetCompilationAsync() .Result; Func <CodeAnalysis.Compilation, CodeAnalysis.Compilation> func = (c) => { return(c); }; var reflectedTypesProvider = new ReflectedTypesProvider( compilation, func, _projectContext, _loader, _logger); var carType = reflectedTypesProvider.GetReflectedType("Library1.Models.Car", false); Assert.Null(carType); carType = reflectedTypesProvider.GetReflectedType("Library1.Models.Car", true); Assert.NotNull(carType); } }
private async Task <Type> FindExistingType(string type) { if (_reflectedTypesProvider == null) { var compilation = await _workspace.CurrentSolution.Projects .Where(p => p.AssemblyName == _projectContext.AssemblyName) .First() .GetCompilationAsync(); _reflectedTypesProvider = new ReflectedTypesProvider( compilation, null, _projectContext, _loader, _logger); if (_reflectedTypesProvider.GetCompilationErrors() != null && _reflectedTypesProvider.GetCompilationErrors().Any()) { // Failed to build the project. throw new InvalidOperationException( string.Format(MessageStrings.CompilationFailedMessage, Environment.NewLine, string.Join(Environment.NewLine, _reflectedTypesProvider.GetCompilationErrors()))); } } var reflectedType = _reflectedTypesProvider.GetReflectedType(type, true); return(reflectedType); }
private async Task <Type> FindExistingType(string dbContext) { var compilation = await _workspace.CurrentSolution.Projects .Where(p => p.AssemblyName == _projectContext.AssemblyName) .First() .GetCompilationAsync(); var reflectedTypesProvider = new ReflectedTypesProvider( compilation, null, _projectContext, _loader, _logger); if (reflectedTypesProvider.GetCompilationErrors() != null && reflectedTypesProvider.GetCompilationErrors().Any()) { // Failed to build the project. throw new InvalidOperationException( string.Format("Failed to compile the project in memory{0}{1}", Environment.NewLine, string.Join(Environment.NewLine, reflectedTypesProvider.GetCompilationErrors()))); } var dbContextType = reflectedTypesProvider.GetReflectedType(dbContext, true); return(dbContextType); }