Copied to clipboard

Flag this post as spam?

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


  • nojaf 91 posts 300 karma points
    Nov 30, 2013 @ 14:14
    nojaf
    0

    Code gen general

    Hi,

    I'm look for a tool that scans my DataTypes and creates c# classes of it.

    Now I'm doing this by hand and it's taking way to much time.

    How can I get CodeGen up and running on a 6.12 installation.

    Also I have no knowledge what uSync is.

    Cheers,

    nojaf

  • nojaf 91 posts 300 karma points
    Dec 02, 2013 @ 12:22
    nojaf
    0

    Ok I've managed to install the Codegen package. And I got everything running. But unfortunately the generated code doesn't fit my needs.

    I was hoping that the properties would look like:

    code

    public WhatEver SomeName{
       get{
              return Convert.ToWhatEver(_iContent.Get("TheAlias"));
          }
       set{
              _iContent.SetValue("TheAlias", value);
          }
    }
    

    I really need a Setter to all the classes. And what I also miss is a list of Child items if so defined.

    Don't get me wrong, the package is amazing but it's unusable for the project I'm building.

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 8x c-trib
    Dec 02, 2013 @ 14:52
    Lars-Erik Aabech
    0

    Good to hear that you got it running.
    Alas, it's a bit tricky to get everything right for now.
    The "real" typed model support in Umbraco isn't in the core for 6.1.x, so you'll have to make your own default controller etc.
    If you're brave enough to run on 6.2 nightly, you can use the "WhileWaitingForSixTwo" project from my 7.0.modelsupport branch.
    That will give you the models as IPublishedContent implementations, and they have .Children of the typed models. You can for instance do:

    @inherits UmbracoViewPage<Page>
    <ul>
    @foreach(var post in Model.Children.OfType<Post>())
    {
        <li>@post.PostProperty</li>
    }
    </ul>
    

    If you need setters, you can create your own property body generator class and override the factory used by codegen. Basically you can have whatever code you want if you do the (small amount of) work needed.

    See https://github.com/lars-erik/Umbraco.CodeGen/wiki/Parsing-and-Generating-code

    Here's the code that currently generates the property body: https://github.com/lars-erik/Umbraco.CodeGen/blob/master/Umbraco.CodeGen/Generators/PropertyBodyGenerator.cs

    If it's too much work for you, stay tuned for coming Umbraco releases for full-fledged support. :)
    (6.2+, 7.?)

Please Sign in or register to post replies

Write your reply to:

Draft