How to deal with customisations in Info classes

support Quba asked on May 2, 2019 12:22

Often when creating custom classes I need to make modifications to the Info class constructor - for example, setting the order number column. As far as I can tell, you can't do this kind of thing in a separate partial class which is where most of my customisations live. The problem is that when I generate and save the code after adding a new field, these changes get overwritten.

My current approach is to manually re-add the code by using my VCS's diff tool, but this is quite error-prone and on a number of occasions developers (including me!) have committed the code without checking and wiped customisations.

Does anyone have a better solution to this problem?

Recent Answers


Roman Hutnyk answered on May 2, 2019 14:28

When I add new fields and generate code file I copy only new fields - quite similar approach to yours.

Another approach would be to leave generated code as is and implement some helper that will use Info class, but also introduce any customization you need - let's call it business logic layer.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 2, 2019 14:55

If you're using source control it should be pretty easy to get a delta on what has changed. If not then don't regenerate the code, simply add the fields manually to your existing class and rebuild. If you want to create custom methods or extend the Provider class, then simply add those customizations to the class you need keeping in mind to not regenerate that code from the Kentico UI.

Get in a standard practice of creating your classes in the UI then gerating your code only 1 time to get the majority of the base code written for you. This is our common practice. Then you know once the code is generated, you simply make your changes to the UI and/or code without generating the code again.

1 votesVote for this answer Mark as a Correct answer

Ji Pattison-Smith answered on May 10, 2019 11:55 (last edited on May 10, 2019 11:55)

Thanks for the suggestions both. It looks like the only way is doing this manually then and having a "best practice" approach, which is fine, I was just wondering if I was missing something which would make this more automated.

(Btw - it was me that asked this question but I accidentally used the company account!)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.