/// <summary> /// Defines a feature on which the calling <see cref="CompilationEditor"/> is dependant. /// </summary> public static void DefineFeatureDependency(this CompilationEditor editor, string feature, string value = "True") { IDictionary <string, string> GetDefaultValue() { editor.GetRecomputationPipeline().Add(next => { return(opts => { if (editor.SharedStorage.TryGet(Key, out IDictionary <string, string> features)) { opts = opts.WithFeatures(opts.Features.Concat(features)); } return next(opts); }); }); return(new Dictionary <string, string>()); } editor.SharedStorage.GetOrAdd(Key, GetDefaultValue)[feature] = value; }
/// <summary> /// Defines a constant to be used as a preprocessor symbol name when parsing syntax trees. /// </summary> public static void DefineConstant(this CompilationEditor editor, string constant) { IList <string> GetDefaultValue() { editor.GetRecomputationPipeline().Add(next => { return(opts => { if (editor.SharedStorage.TryGet(Key, out IList <string> preprocessorSymbolNames)) { opts = opts.WithPreprocessorSymbols(opts.PreprocessorSymbolNames.Concat(preprocessorSymbolNames)); } return next(opts); }); }); return(new LightList <string>()); } editor.SharedStorage.GetOrAdd(Key, GetDefaultValue).Add(constant); }
/// <summary> /// Returns a copy of the given <see cref="SyntaxTree"/>, with its options compatible /// with Cometary's required options. /// </summary> public static SyntaxTree WithCometaryOptions(this CSharpSyntaxTree syntaxTree, CompilationEditor editor) { return(syntaxTree.WithOptions(editor.GetRecomputationPipeline().MakeDelegate(opts => opts)(syntaxTree.Options))); }