public void RegenerateAssembly() { OnRegeneratingAssembly(); if (GeneratedAssemblyUpToDate) { return; } CompilationResult compilationResult = TheCompilation.GetCompilationResult(); if (!compilationResult.Success) { if (!_pathToSaveToOnError.IsNullOrEmpty()) { this.SaveToPath(_pathToSaveToOnError); } throw new Exception($"Compilation Error: {compilationResult.TheErrors.StrConcat(null, "\n\n")}"); } TheGeneratedAssembly = Assembly.Load(compilationResult.TheResult); OnAssemblyRegenerated(); GeneratedAssemblyUpToDate = true; }
protected void UpdateCompilation(string docName, string code) { Document newDoc = TheWorkspace.AddDocument(docName, code); this.TheProj = TheWorkspace.CurrentProj; SyntaxTree syntaxTree = newDoc.GetSyntaxTreeAsync().Result; TheCompilation = TheCompilation.AddSyntaxTrees(syntaxTree); }
public void SetInit ( INamedTypeSymbol initTypeSymbol ) { ForceCreateSetter = true; if (!TheCompilation.CanBeConvertedImplicitly(initTypeSymbol, this.WrapperTypeSymbol)) { throw new Exception($"Roxy Usage Error: Cannot initialize property '{WrapperSymbol.Name}' to type '{initTypeSymbol.GetFullTypeString()}'"); } TheInitTypeSymbol = initTypeSymbol; this.AddBackingField = true; }
internal void AddAssembliesToReference <T>(IEnumerable <T> assemblyInfos, Func <T, AssemblyIdentity> toId, Func <T, MetadataReference> toMDReference) { IEnumerable <AssemblyIdentity> newAssemblyIds = assemblyInfos.Select(assemblySymbol => toId(assemblySymbol)).Except(TheCompilation.ReferencedAssemblyNames).ToList(); IEnumerable <T> newAssemblies = assemblyInfos.Where(aSymbol => newAssemblyIds.Contains(toId(aSymbol))).ToList(); if (newAssemblies.IsNullOrEmpty()) { return; } IEnumerable <MetadataReference> allMetadataReferences = TheCompilation.References.Union(newAssemblies.SelectMany(assemblySymbol => toMDReference(assemblySymbol).ToCollection())).ToList(); TheProj = TheProj.WithMetadataReferences(allMetadataReferences); TheCompilation = TheCompilation.WithReferences(allMetadataReferences); }
internal void AddAssembliesToReference(IEnumerable <Assembly> assemblies) { IEnumerable <Assembly> newAssemblies = assemblies.Except(this.AllReferencedAssemblies); if (newAssemblies.IsNullOrEmpty()) { return; } newAssemblies.DoForEach(assembly => AllReferencedAssemblies.Add(assembly)); MetadataReference[] newReferences = newAssemblies.Select(assmbly => assmbly.ToRef()).ToArray(); MetadataReference[] allReferences = AllReferencedAssemblies.Select(assmbly => assmbly.ToRef()).ToArray(); TheProj = TheProj.WithMetadataReferences(allReferences); TheCompilation = TheCompilation.WithReferences(allReferences); }