modelsbuilder/ModelsBuilder.Original

Supports tuple literals?

Closed this issue · 3 comments

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."

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.

My bad. Should have provided that.

  • Tuple literals were released in c# 7.0
  • Running Umbraco 7.14, ModelsBuilder 3.0.10

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

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.