Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generator samples to latest version of the API #625

Merged
merged 1 commit into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<UsingToolNetFrameworkReferenceAssemblies>true</UsingToolNetFrameworkReferenceAssemblies>
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
<UsingToolSymbolUploader>true</UsingToolSymbolUploader>
<MicrosoftNetCompilersToolsetVersion>3.7.0-4.20351.2</MicrosoftNetCompilersToolsetVersion>
<MicrosoftNetCompilersToolsetVersion>3.8.0-4.20464.1</MicrosoftNetCompilersToolsetVersion>
<!-- Force prior version due to https://github.com/microsoft/vstest/pull/2192 and https://github.com/microsoft/vstest/pull/2067 -->
<MicrosoftNETTestSdkVersion>16.1.1</MicrosoftNETTestSdkVersion>
<!-- Dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public AutoNotifyAttribute()
}
";

public void Initialize(InitializationContext context)
public void Initialize(GeneratorInitializationContext context)
{
// Register a syntax receiver that will be created for each generation pass
context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
}

public void Execute(SourceGeneratorContext context)
public void Execute(GeneratorExecutionContext context)
{
// add the attribute text
context.AddSource("AutoNotifyAttribute", SourceText.From(attributeText, Encoding.UTF8));
Expand Down Expand Up @@ -75,7 +75,7 @@ public void Execute(SourceGeneratorContext context)
}
}

private string ProcessClass(INamedTypeSymbol classSymbol, List<IFieldSymbol> fields, ISymbol attributeSymbol, ISymbol notifySymbol, SourceGeneratorContext context)
private string ProcessClass(INamedTypeSymbol classSymbol, List<IFieldSymbol> fields, ISymbol attributeSymbol, ISymbol notifySymbol, GeneratorExecutionContext context)
{
if (!classSymbol.ContainingSymbol.Equals(classSymbol.ContainingNamespace, SymbolEqualityComparer.Default))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static string StringToValidPropertyName(string s)
static IEnumerable<(string, string)> SourceFilesFromAdditionalFiles(IEnumerable<(CsvLoadType loadTime, bool cacheObjects, AdditionalText file)> pathsData)
=> pathsData.SelectMany(d => SourceFilesFromAdditionalFile(d.loadTime, d.cacheObjects, d.file));

static IEnumerable<(CsvLoadType, bool, AdditionalText)> GetLoadOptions(SourceGeneratorContext context)
static IEnumerable<(CsvLoadType, bool, AdditionalText)> GetLoadOptions(GeneratorExecutionContext context)
{
foreach (AdditionalText file in context.AdditionalFiles)
{
Expand All @@ -169,15 +169,15 @@ static string StringToValidPropertyName(string s)
}
}

public void Execute(SourceGeneratorContext context)
public void Execute(GeneratorExecutionContext context)
{
IEnumerable<(CsvLoadType, bool, AdditionalText)> options = GetLoadOptions(context);
IEnumerable<(string, string)> nameCodeSequence = SourceFilesFromAdditionalFiles(options);
foreach ((string name, string code) in nameCodeSequence)
context.AddSource($"Csv_{name}", SourceText.From(code, Encoding.UTF8));
}

public void Initialize(InitializationContext context)
public void Initialize(GeneratorInitializationContext context)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SourceGeneratorSamples
[Generator]
public class HelloWorldGenerator : ISourceGenerator
{
public void Execute(SourceGeneratorContext context)
public void Execute(GeneratorExecutionContext context)
{
// begin creating the source we'll inject into the users compilation
StringBuilder sourceBuilder = new StringBuilder(@"
Expand Down Expand Up @@ -43,7 +43,7 @@ public static void SayHello()
context.AddSource("helloWorldGenerated", SourceText.From(sourceBuilder.ToString(), Encoding.UTF8));
}

public void Initialize(InitializationContext context)
public void Initialize(GeneratorInitializationContext context)
{
// No initialization required
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Mustache
[Generator]
public class MustacheGenerator : ISourceGenerator
{
public void Execute(SourceGeneratorContext context)
public void Execute(GeneratorExecutionContext context)
{
string attributeSource = @"
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)]
Expand Down Expand Up @@ -64,7 +64,7 @@ public MustacheAttribute(string name, string template, string hash)
ExpressionSyntax expr = arg.Expression;

TypeInfo t = m.GetTypeInfo(expr);
Optional<object> v = m.GetConstantValue(expr);
Optional<object?> v = m.GetConstantValue(expr);
if (index == 0)
{
mustacheName = v.ToString();
Expand Down Expand Up @@ -116,7 +116,7 @@ public static partial class Constants {{

}

public void Initialize(InitializationContext context)
public void Initialize(GeneratorInitializationContext context)
{
// No initialization required
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class XmlSettings
}
}
";
public void Execute(SourceGeneratorContext context)
public void Execute(GeneratorExecutionContext context)
{
// Using the context, get any additional files that end in .xmlsettings
IEnumerable<AdditionalText> settingsFiles = context.AdditionalFiles.Where(at => at.Path.EndsWith(".xmlsettings"));
Expand All @@ -31,7 +31,7 @@ public void Execute(SourceGeneratorContext context)
}
}

private void ProcessSettingsFile(AdditionalText xmlFile, SourceGeneratorContext context)
private void ProcessSettingsFile(AdditionalText xmlFile, GeneratorExecutionContext context)
{
// try and load the settings file
XmlDocument xmlDoc = new XmlDocument();
Expand Down Expand Up @@ -101,7 +101,7 @@ public class {name}Settings
context.AddSource($"Settings_{name}", SourceText.From(sb.ToString(), Encoding.UTF8));
}

public void Initialize(InitializationContext context)
public void Initialize(GeneratorInitializationContext context)
{
}
}
Expand Down