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

add vb generator samples to the samples solution #830

Merged
merged 10 commits into from
Jun 1, 2021
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
23 changes: 20 additions & 3 deletions Samples.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28606.18
Expand Down Expand Up @@ -113,9 +113,15 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "VisualBasicToCSharpConverte
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceGenerators", "SourceGenerators", "{14D18F51-6B59-49D5-9AB7-08B38417A459}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGeneratorSamples", "samples\CSharp\SourceGenerators\SourceGeneratorSamples\SourceGeneratorSamples.csproj", "{2ADE5CFA-5DF4-44A9-BD67-E884BCFBA045}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpSourceGeneratorSamples", "samples\CSharp\SourceGenerators\SourceGeneratorSamples\CSharpSourceGeneratorSamples.csproj", "{2ADE5CFA-5DF4-44A9-BD67-E884BCFBA045}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneratedDemo", "samples\CSharp\SourceGenerators\GeneratedDemo\GeneratedDemo.csproj", "{EC4DB63B-C2B4-4D06-AF98-15253035C6D5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpGeneratedDemo", "samples\CSharp\SourceGenerators\GeneratedDemo\CSharpGeneratedDemo.csproj", "{EC4DB63B-C2B4-4D06-AF98-15253035C6D5}"
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "VisualBasicGeneratedDemo", "samples\VisualBasic\SourceGenerators\GeneratedDemo\VisualBasicGeneratedDemo.vbproj", "{DA924876-9CF5-47E0-AA01-ADAF47653D39}"
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "VisualBasicSourceGeneratorSamples", "samples\VisualBasic\SourceGenerators\SourceGeneratorSamples\VisualBasicSourceGeneratorSamples.vbproj", "{8322B6E4-0CB1-4EC1-A2CC-2E4DB02C834A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceGenerators", "SourceGenerators", "{E79B07C8-0859-4B5C-9650-68D855833C6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -283,6 +289,14 @@ Global
{EC4DB63B-C2B4-4D06-AF98-15253035C6D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC4DB63B-C2B4-4D06-AF98-15253035C6D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC4DB63B-C2B4-4D06-AF98-15253035C6D5}.Release|Any CPU.Build.0 = Release|Any CPU
{DA924876-9CF5-47E0-AA01-ADAF47653D39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA924876-9CF5-47E0-AA01-ADAF47653D39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA924876-9CF5-47E0-AA01-ADAF47653D39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA924876-9CF5-47E0-AA01-ADAF47653D39}.Release|Any CPU.Build.0 = Release|Any CPU
{8322B6E4-0CB1-4EC1-A2CC-2E4DB02C834A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8322B6E4-0CB1-4EC1-A2CC-2E4DB02C834A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8322B6E4-0CB1-4EC1-A2CC-2E4DB02C834A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8322B6E4-0CB1-4EC1-A2CC-2E4DB02C834A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -342,6 +356,9 @@ Global
{14D18F51-6B59-49D5-9AB7-08B38417A459} = {C3FB27E9-C8EE-4F76-B0AA-7CD67A7E652B}
{2ADE5CFA-5DF4-44A9-BD67-E884BCFBA045} = {14D18F51-6B59-49D5-9AB7-08B38417A459}
{EC4DB63B-C2B4-4D06-AF98-15253035C6D5} = {14D18F51-6B59-49D5-9AB7-08B38417A459}
{DA924876-9CF5-47E0-AA01-ADAF47653D39} = {E79B07C8-0859-4B5C-9650-68D855833C6E}
{8322B6E4-0CB1-4EC1-A2CC-2E4DB02C834A} = {E79B07C8-0859-4B5C-9650-68D855833C6E}
{E79B07C8-0859-4B5C-9650-68D855833C6E} = {CDA94F62-E35A-4913-8045-D9D42416513C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B849838B-3D7A-4B6B-BE07-285DCB1588F4}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SourceGeneratorSamples\SourceGeneratorSamples.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\SourceGeneratorSamples\CSharpSourceGeneratorSamples.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<!-- Manually reference the generator props because we locally reference the generator. When added via NuGet this happens automatically -->
Expand Down
28 changes: 11 additions & 17 deletions samples/VisualBasic/SourceGenerators/GeneratedDemo/Program.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,30 @@ Option Infer On

Module Program

Public Sub Main()
Public Sub Main()

Console.WriteLine("Running HelloWorld:
Console.WriteLine("Running HelloWorld:
")
UseHelloWorldGenerator.Run()
UseHelloWorldGenerator.Run()

Console.WriteLine("
Console.WriteLine("

Running AutoNotify:
")
UseAutoNotifyGenerator.Run()
UseAutoNotifyGenerator.Run()

Console.WriteLine("
Console.WriteLine("

Running XmlSettings:
")
UseXmlSettingsGenerator.Run()
UseXmlSettingsGenerator.Run()

Console.WriteLine("
Console.WriteLine("

Running CsvGenerator:
")
UseCsvGenerator.Run()
UseCsvGenerator.Run()

Console.WriteLine("
End Sub

Running MustacheGenerator:
")
UseMustacheGenerator.Run()

End Sub

End Module
End Module
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ Imports AutoNotify
' The view model we'd like to augment
Partial Public Class ExampleViewModel

<AutoNotify>
Private _text As String = "private field text"
<AutoNotify>
Private _text As String = "private field text"

<AutoNotify(PropertyName:="Count")>
Private _amount As Integer = 5
<AutoNotify(PropertyName:="Count")>
Private _amount As Integer = 5

End Class

Public Module UseAutoNotifyGenerator

Public Sub Run()
Public Sub Run()

Dim vm As New ExampleViewModel()
Dim vm As New ExampleViewModel()

' we didn't explicitly create the 'Text' property, it was generated for us
Dim text = vm.Text
Console.WriteLine($"Text = {text}")
' we didn't explicitly create the 'Text' property, it was generated for us
Dim text = vm.Text
Console.WriteLine($"Text = {text}")

' Properties can have differnt names generated based on the PropertyName argument of the attribute
Dim count = vm.Count
Console.WriteLine($"Count = {count}")
' Properties can have differnt names generated based on the PropertyName argument of the attribute
Dim count = vm.Count
Console.WriteLine($"Count = {count}")

' the viewmodel will automatically implement INotifyPropertyChanged
AddHandler vm.PropertyChanged, Sub(o, e) Console.WriteLine($"Property {e.PropertyName} was changed")
vm.Text = "abc"
vm.Count = 123
' the viewmodel will automatically implement INotifyPropertyChanged
AddHandler vm.PropertyChanged, Sub(o, e) Console.WriteLine($"Property {e.PropertyName} was changed")
vm.Text = "abc"
vm.Count = 123

' Try adding fields to the ExampleViewModel class above and tagging them with the <AutoNotify> attribute
' You'll see the matching generated properties visibile in IntelliSense in realtime
' Try adding fields to the ExampleViewModel class above and tagging them with the <AutoNotify> attribute
' You'll see the matching generated properties visibile in IntelliSense in realtime

End Sub
End Sub

End Module
End Module
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Imports CSV

Friend Class UseCsvGenerator

Public Shared Sub Run()
Public Shared Sub Run()

Console.WriteLine("## CARS")
Cars.All.ToList().ForEach(Sub(c) Console.WriteLine(c.Brand & vbTab & c.Model & vbTab & c.Year & vbTab & c.Cc & vbTab & c.Favorite))
Console.WriteLine(vbCr & "## PEOPLE")
People.All.ToList().ForEach(Sub(p) Console.WriteLine(p.Name & vbTab & p.Address & vbTab & p._11Age))
Console.WriteLine("## CARS")
Cars.All.ToList().ForEach(Sub(c) Console.WriteLine(c.Brand & vbTab & c.Model & vbTab & c.Year & vbTab & c.Cc & vbTab & c.Favorite))
Console.WriteLine(vbCr & "## PEOPLE")
People.All.ToList().ForEach(Sub(p) Console.WriteLine(p.Name & vbTab & p.Address & vbTab & p._11Age))

End Sub
End Sub

End Class
End Class
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Public Module UseHelloWorldGenerator

Public Sub Run()
' The static call below is generated at build time, and will list the syntax trees used in the compilation
HelloWorldGenerated.HelloWorld.SayHello()
End Sub
Public Sub Run()
' The static call below is generated at build time, and will list the syntax trees used in the compilation
HelloWorldGenerated.HelloWorld.SayHello()
End Sub

End Module

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

Public Module UseXmlSettingsGenerator

Public Sub Run()
Public Sub Run()

' This XmlSettings generator makes a static property in the XmlSettings class for each .xmlsettings file
' This XmlSettings generator makes a static property in the XmlSettings class for each .xmlsettings file

' here we have the 'Main' settings file from MainSettings.xmlsettings
' the name is determined by the 'name' attribute of the root settings element
Dim main As XmlSettings.MainSettings = XmlSettings.Main
Console.WriteLine($"Reading settings from {main.GetLocation()}")
' here we have the 'Main' settings file from MainSettings.xmlsettings
' the name is determined by the 'name' attribute of the root settings element
Dim main As XmlSettings.MainSettings = XmlSettings.Main
Console.WriteLine($"Reading settings from {main.GetLocation()}")

' settings are strongly typed and can be read directly from the static instance
Dim firstRun As Boolean = XmlSettings.Main.FirstRun
Console.WriteLine($"Setting firstRun = {firstRun}")
' settings are strongly typed and can be read directly from the static instance
Dim firstRun As Boolean = XmlSettings.Main.FirstRun
Console.WriteLine($"Setting firstRun = {firstRun}")

Dim cacheSize As Integer = XmlSettings.Main.CacheSize
Console.WriteLine($"Setting cacheSize = {cacheSize}")
Dim cacheSize As Integer = XmlSettings.Main.CacheSize
Console.WriteLine($"Setting cacheSize = {cacheSize}")

' Try adding some keys to the settings file and see the settings become available to read from
' Try adding some keys to the settings file and see the settings become available to read from

End Sub
End Sub

End Module
End Module
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SourceGeneratorSamples\SourceGeneratorSamples.vbproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\SourceGeneratorSamples\VisualBasicSourceGeneratorSamples.vbproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<!-- Manually reference the generator props because we locally reference the generator. When added via NuGet this happens automatically -->
Expand Down
Loading