UML Class Diagram - Instant Generator C# - access modifiers on properties setters


I’m trying to use VP’s UML diagram and then generate C# code from it using instant generator. I’d like to have the possibility to set my properties setters as protected (while leaving the getter public). Is there anyway to do so?



Hi Samuel,

I’m not familiar with using instant generator, but I believe you can achieve what you want by implementing your custom template:

The C# template files are located at <vp_installation_directory>\resources\instantgenerator\csharp, the file you should customize would be “property.vm”. You are recommended to copy the while template directory instead of modifying the original.

Here is one way I tried that works for me but I believe it is not the only way. I added a tagged value to the attribute named “setterVisibility” and set its value to “protected”:


And then I update the line of code related to generating setter as follow:

In the instant generator dialog box, point “Template directory” to your own instead of the default one. You can see the setter now become protected:


Hope this could help,


1 Like