modelsbuilder / ModelsBuilder.Original

The Community Models Builder for Umbraco
MIT License
114 stars 49 forks source link

Supports tuple literals? #203

Closed dnwhte closed 5 years ago

dnwhte commented 5 years ago

I'm trying to extend the generated Image model with the following.

    public partial class Image
    {
        public (double wh, double hw) Ratio
        {
            get
            {
                double width;
                double height;

                if (double.TryParse(this.UmbracoWidth, out width) && double.TryParse(this.UmbracoHeight, out height))
                {
                    double wh = width / height;
                    double hw = height / width;
                    return (wh, hw);
                }

                return (0, 0);
            }
        }
    }

I believe the generator is having issues with tuple literals. It works if I use a more traditional approach (like a ratio class).

The extend class does work, but I cannot regenerate models. I get this generic error: "The custom tool 'UmbracoModelsBuilder' failed. One or more errors occurred."

zpqrtbnk commented 5 years ago

What version of ModelsBuilder are you running? The tuple literals was introduced in c# version ? and may not be supported by the ModelsBuilder version you are running.

dnwhte commented 5 years ago

My bad. Should have provided that.

I'm assuming ModelsBuilder 8.X,X is for Umbraco v8?

zpqrtbnk commented 5 years ago

So... Tuples Literals are not supported by ModelsBuilder 3.0.10. ModelsBuilder 8.x is indeed for Umbraco 8.x but there is a ModelsBuilder 3.1 version which relies on the latest Roslyn packages and therefore supports Tuple Literals.

Disclaimer: running the latest Roslyn packages on anything prior to .Net Framework 4.7.2 can be tricky, which is why this is not the official MB version for Umbraco v7.