Skip to content

Commit

Permalink
Update generator samples to latest version of the API
Browse files Browse the repository at this point in the history
  • Loading branch information
chsienki committed Sep 14, 2020
1 parent 02129f8 commit 605b257
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
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>
<!-- Dependencies -->
<!-- Roslyn for VS 2019 -->
<!-- NOTE: Do not upgrade these to be newer than what shipped in VS 2019 since the Syntax Visualizer extension still
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

0 comments on commit 605b257

Please sign in to comment.