|
1 | 1 | # SourceCodeGenerators
|
2 |
| -Repository of my source code generators |
| 2 | + |
| 3 | +This repository contains a set of Code generators, see bekow. |
| 4 | + |
| 5 | + |
| 6 | +## General Usage |
| 7 | + |
| 8 | +To enable the source code generators you have to change the project file. |
| 9 | + |
| 10 | +```xml |
| 11 | +<ItemGroup> |
| 12 | + <ProjectReference |
| 13 | + Include="..\SourceGenerator\SourceGenerator.csproj" |
| 14 | + ReferenceOutputAssembly="false" |
| 15 | + OutputItemType="Analyzer" /> |
| 16 | +</ItemGroup> |
| 17 | +``` |
| 18 | + |
| 19 | +## AutoNotifyGenerator |
| 20 | + |
| 21 | +Auto implemenation for [`INotifyPropertyChanged`](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged). You only have to specify the field and mark the field with |
| 22 | +the attribute and generator will automatically generate the property and raise the event. |
| 23 | + |
| 24 | +```csharp |
| 25 | +public partial class ExampleViewModel |
| 26 | +{ |
| 27 | + [AutoNotify] |
| 28 | + private string _text = "private field text"; |
| 29 | + |
| 30 | + [AutoNotify(PropertyName = "Count")] |
| 31 | + private int _amount = 5; |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | + becomes |
| 36 | + |
| 37 | +```csharp |
| 38 | +public class ExampleViewModel : INotifyPropertyChanged |
| 39 | +{ |
| 40 | + [AutoNotify] |
| 41 | + private string _text = "private field text"; |
| 42 | + |
| 43 | + [AutoNotify(PropertyName = "Count")] |
| 44 | + private int _amount = 5; |
| 45 | + |
| 46 | + public string Text |
| 47 | + { |
| 48 | + get { return _text; } |
| 49 | + set |
| 50 | + { |
| 51 | + string old = _text; |
| 52 | + _text = value; |
| 53 | + if (_text != old) |
| 54 | + { |
| 55 | + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Text")); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + public int Count |
| 61 | + { |
| 62 | + get { return _amount; } |
| 63 | + set |
| 64 | + { |
| 65 | + int old = _amount; |
| 66 | + _amount = value; |
| 67 | + if (_amount != old) |
| 68 | + { |
| 69 | + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count")); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + public event PropertyChangedEventHandler PropertyChanged; |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +## Usage |
| 78 | + |
| 79 | +Hook up the generator, nothing else to do. |
| 80 | + |
| 81 | +## FixXmlEnumConverter |
| 82 | + |
| 83 | +This generator shall generate enumerations based on the definition of the xml-based |
| 84 | +FIX application dictionary. Usually used for QuickFix. |
| 85 | +The fields in the xml will be converted to an enum field and tag number. Additional enums |
| 86 | +will be generated for the fix field enums. Because the value can be char instead of int, the |
| 87 | +enum value is the char code. |
| 88 | + |
| 89 | +### Usage |
| 90 | + |
| 91 | +Reference the code generator as usual. The add the xml files you like to be converted. |
| 92 | +In VS set the `Build Action` property of the xml to `C# analyzer additional file`. |
| 93 | +Alternatively you can edit the project file and add the following code block. |
| 94 | + |
| 95 | +```xml |
| 96 | +<ItemGroup> |
| 97 | + <AdditionalFiles Include="TT-FIX42.xml" /> |
| 98 | +</ItemGroup> |
| 99 | +``` |
0 commit comments