Results 1 to 8 of 8

Thread: Creating VB.NET Records: The magic of Roslyn and source generators!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Creating VB.NET Records: The magic of Roslyn and source generators!


    I created a Record Generator to allow you to use Records in your VB.NET prpjects.
    These are three possible variations of the record syntax:
    Code:
    Public Record NameValue(Name ="", Value = 0.0)
    
    Public ReadOnly Structure ROStruct(X$, Y%, Z@)
    
    Friend ReadOnly Class ROClass(A As Integer, B As Integer)
    To use the Record Generator:
    1. Add the NuGet package to your project.
      PM> Install-Package Visual-Basic-Record-Generator
    2. Add one or more text files to your project, and change there extension to .rec.
    3. Right-click the .rec file in the Solution Explorer and click Properties, then from the 'Build Action' dropdown list choose VB analyzer additional file and save the changes.
    4. Write the one or more record syntax in each .rec file and save the changes. The generator will generate the record classes/structures immediately for you, and you can use them in your code as a part of your project.


    For more info on record syntax, see the `Read Me` on the source code repo on github:

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,461

    Re: Creating VB.NET Records: The magic of Roslyn and source generators!

    Moderator actions - Moved thread to Visual Basic .NET codebank, replaced markdown with BB tags, and removed the obnoxiously large font size.
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Creating VB.NET Records: The magic of Roslyn and source generators!

    Quote Originally Posted by dday9 View Post
    Moderator actions - Moved thread to Visual Basic .NET codebank, replaced markdown with BB tags, and removed the obnoxiously large font size.
    That's OK. Thanks.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,484

    Re: Creating VB.NET Records: The magic of Roslyn and source generators!

    Man, I really need to learn how to use stuff like this. There is so much potential with these compilation toolset.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,461

    Re: Creating VB.NET Records: The magic of Roslyn and source generators!

    Doesn't PetaPoco do something similar using T4 templates or is this something completely different?
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Creating VB.NET Records: The magic of Roslyn and source generators!

    Quote Originally Posted by Niya View Post
    Man, I really need to learn how to use stuff like this. There is so much potential with these compilation toolset.
    You can start here:
    https://github.com/DualBrain/Samples...urceGenerators

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Creating VB.NET Records: The magic of Roslyn and source generators!

    Quote Originally Posted by dday9 View Post
    Doesn't PetaPoco do something similar using T4 templates or is this something completely different?
    Source generators can take actions based on the vb source code, and make use of the syntax tree and the compilation/semantics of the current context. This is way advanced than T4 which can only generate code based on a text template. See the samples I posted in the above reply.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Creating VB.NET Records: The magic of Roslyn and source generators!

    By the way, this my first try to generate vb records:
    https://github.com/VBAndCs/VB-Record-Generator
    It just uses a text template. It is just an utility and you have to copy the generated record and add it to your project manually. The source generators version is more advances, and it is easy to modify the record definition as it is a part of the project. It can infer param types from their default values, and solved the missing optional param confusion by using Nullable/Optional Structures. In the old version, I just added ? for all params and you must fix the errors when the param type is a reference type because I can't know that without information about your project and its references. Source generators makes this possible.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width