Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • higgsy 65 posts 92 karma points
    Apr 05, 2016 @ 20:05
    higgsy
    0

    Adding manual properties into ModelsBuilder generated classes

    Hi all,

    I'm using the ModelsBuilder for the first time and loving it! It's really fantastic.

    One issue that I can't get my head round is how I can add properties into the generated classes without them being removed when I re-run the VS custom tool. My use case here is essentially a ViewModel - the generated classes are being populated with the data from umbraco, thats fine, but in certain scenario's I want to add properties into the generated classes before passing them to the view from the controller. i.e. I'll manipulate those manual properties in the controller.

    This post seems to highlight a similar topic, but i dont think it's quite the same as my scenario (or i can't quite understand it).

    Is what I'm asking possible?

    Thanks for your time in advance higgsy

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 05, 2016 @ 20:13
    Jeavon Leopold
    100

    Hi Higgsy,

    The generated classes are partial so that you can add your own partial classes in separate files so they don't get over written.

    Check out the documentation here https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Understand-And-Extend

    Jeavon

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 05, 2016 @ 20:15
    Jeavon Leopold
    0

    p.s Extending section

  • higgsy 65 posts 92 karma points
    Apr 05, 2016 @ 20:26
    higgsy
    0

    So all I had to do was to create a new Partial Class with the same name and constructor as was previously generated by the custom tool - and voila, are you really telling me that's all there is to it - that is absolutely genius!!!!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 05, 2016 @ 21:10
    Jeavon Leopold
    0

    Yes, exactly!

  • higgsy 65 posts 92 karma points
    Apr 05, 2016 @ 21:13
    higgsy
    0

    Absolutely genius - umbraco gets better every day. Thanks for your help - greatly appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft