# VBForums CodeBank > CodeBank - Visual Basic .NET >  Creating VB.NET Records: The magic of Roslyn and source generators!

## M.Hamdy

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:


```
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:*
 Add the NuGet package to your project.
PM> Install-Package Visual-Basic-Record-Generator Add one or more text files to your project, and change there extension to .rec. 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. 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:

----------


## dday9

_Moderator actions - Moved thread to Visual Basic .NET codebank, replaced markdown with BB tags, and removed the obnoxiously large font size._

----------


## M.Hamdy

> _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.

----------


## Niya

Man, I really need to learn how to use stuff like this. There is so much potential with these compilation toolset.

----------


## dday9

Doesn't PetaPoco do something similar using T4 templates or is this something completely different?

----------


## M.Hamdy

> 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

----------


## M.Hamdy

> 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.

----------


## M.Hamdy

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.

----------


## M.Hamdy

RecGen is updated to v2.2, to generate the GetHashCode method which is necessary to use the record as a key in dictionaries.
To add the RecGen NuGet package to your project, use:
PM> Install-Package RecGen
Or:
PM> Install-Package Visual-Basic-Record-Generator

----------

