Skip to content

Commit b34d947

Browse files
author
aliev.faramoz
committed
Added ParseOptions for attribute generation
1 parent 5c94503 commit b34d947

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

DevExpress.Mvvm.CodeGenerators.Tests/TestSource/GenerationTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,22 @@ public DelegateCommand<int> Command3Command {
406406

407407
}
408408
#endif
409+
410+
[Test, Category("TODO")]
411+
public void CommonLanguageVersionTest() {
412+
string source = string.Empty;
413+
CSharpParseOptions options = new CSharpParseOptions((LanguageVersion)1000); // TODO Change to LanguageVersion.CSharp10
414+
Compilation inputCompilation = CSharpCompilation.Create("MyCompilation",
415+
new[] { CSharpSyntaxTree.ParseText(source, options) },
416+
new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location)},
417+
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
418+
ViewModelGenerator generator = new ViewModelGenerator();
419+
GeneratorDriver driver = CSharpGeneratorDriver.Create(new[] { generator }, parseOptions: options);
420+
driver = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);
421+
GeneratorDriverRunResult runResult = driver.GetRunResult();
422+
GeneratorRunResult generatorResult = runResult.Results[0];
423+
424+
Assert.AreEqual(1, generatorResult.GeneratedSources.Length);
425+
}
409426
}
410427
}

DevExpress.Mvvm.CodeGenerators/Generators/GeneratorCore.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public static void Execute(GeneratorExecutionContext context) {
2020
return;
2121

2222
SourceText attributesSourceText = SourceText.From(InitializationGenerator.GetSourceCode(ContextInfo.GetIsWinUI(context.Compilation)), Encoding.UTF8);
23-
Compilation compilation = context.Compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(attributesSourceText));
23+
SyntaxTree attributesSyntaxTree = CSharpSyntaxTree.ParseText(attributesSourceText, (CSharpParseOptions)context.ParseOptions);
24+
Compilation compilation = context.Compilation.AddSyntaxTrees(attributesSyntaxTree);
2425
context.AddSource(ClassHelper.CreateFileName("Attributes"), attributesSourceText);
2526

2627
ContextInfo contextInfo = new ContextInfo(context, compilation);

0 commit comments

Comments
 (0)