/// <summary> /// Creates the control builder. /// </summary> private IControlBuilder CreateControlBuilder(MarkupFile file) { var lockId = (file.GetHashCode() & 0x7fffffff) % compilationLocks.Length; // do not compile the same view multiple times lock (compilationLocks[lockId]) { if (controlBuilders.ContainsKey(file)) { return(controlBuilders[file]); } var namespaceName = GetNamespaceFromFileName(file.FileName, file.LastWriteDateTimeUtc); var assemblyName = namespaceName; var className = GetClassFromFileName(file.FileName) + "ControlBuilder"; try { return(ViewCompilerFactory().CompileView(file.ContentsReaderFactory(), file.FileName, assemblyName, namespaceName, className)); } catch (DotvvmCompilationException ex) { if (ex.FileName == null) { ex.FileName = file.FullPath; } else if (!Path.IsPathRooted(ex.FileName)) { ex.FileName = Path.Combine( file.FullPath.Remove(file.FullPath.Length - file.FileName.Length), ex.FileName); } throw; } } }
public void AddFile(string path, string contents) { var mf = new MarkupFile(path, path); (mf.GetType().GetProperty("ReadContent") ?? mf.GetType().GetProperty("ContentsReaderFactory")).SetValue(mf, (Func <string>)(() => contents)); PathToFileMap[path] = mf; }
private static void EvilizeContentReaderFunc(MarkupFile markupFile, Action evilAction) { var evilFunc = new System.Func <string>(() => { evilAction(); return(new MarkupFile(markupFile.FileName, markupFile.FullPath).ContentsReaderFactory()); }); var contentReaderFactoryPropertyInfo = typeof(MarkupFile).GetProperty(nameof(markupFile.ContentsReaderFactory)); contentReaderFactoryPropertyInfo.SetValue(markupFile, evilFunc); }
public void Initialize(IncrementalGeneratorInitializationContext context) { var results = context .AdditionalTextsProvider .Where(x => x.Path.EndsWith(MarkupFileExt, StringComparison.OrdinalIgnoreCase)) .Select((x, ct) => { ct.ThrowIfCancellationRequested(); return(new MarkupFile(x.Path, MarkupFile.ComputeFileHash(x.Path))); }) .WithComparer(MarkupFileEqualityComparer.Default) .Combine(context.CompilationProvider) .Select(static (x, ct) =>