.NET code generators for Kentico Cloud.
Clone or download
Latest commit 3b13c9c Oct 11, 2018

README.md

Build status Forums

Kentico Cloud model generator utility for .NET

This utility generates strongly-typed models based on Content Types in a Kentico Cloud project. The models are supposed to be used together with the Kentico Cloud Delivery SDK for .NET or Kentico Cloud Content Management SDK for .NET. Please read the documentation to see all benefits of this approach.

Get the tool

Windows

Latest release: Download

Note: The application is self-contained. There's no need to install any version of .NET on your machine.

Linux, Mac OS and other platforms

  • Clone the repository
  • Navigate to the cloud-generators-net\src\CloudModelGenerator folder
  • Run dotnet build -r <RID> to build the app
  • Run dotnet publish -c release -r <RID> to publish the app

See the list of all RIDs.

How to use for Delivery SDK

Windows

CloudModelGenerator.exe --projectid "<projectid>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider] [--structuredmodel] [--filenamesuffix "<suffix>"]

Linux, Mac OS and other platforms

dotnet run --projectid "<projectid>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider] [--structuredmodel] [--filenamesuffix "<suffix>"]

Parameters

Parameter (single character variant) Keyword variant Required Default value Description
-p --projectid True null A GUID that can be found in Kentico Cloud -> API keys -> Project ID
-n --namespace False KenticoCloudModels A name of the C# namespace
-o --outputdir False \. An output folder path
-g --generatepartials False null Generates partial classes for customizationfilenames
-t --withtypeprovider False true Indicates whether the CustomTypeProvider class should be generated (see Customizing the strong-type binding logic for more info)
-s --structuredmodel False false Generates IRichTextContent instead of string for rich-text elements. This enables utilizing structured rich-text rendering
-f --filenamesuffix False null Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs)
-b --baseclass False null If provided, a base class type will be created and all generated classes will derive from that base class via partial extender classes

These parameters can also be set via the appSettings.json file located in the same directory as the executable file. Command-line parameters always take precedence.

Example output

using System;
using System.Collections.Generic;
using KenticoCloud.Delivery;

namespace KenticoCloudModels
{
    public partial class CompleteContentType
    {
        public string Text { get; set; }
        public string RichText { get; set; }
        public decimal? Number { get; set; }
        public IEnumerable<MultipleChoiceOption> MultipleChoice { get; set; }
        public DateTime? DateTime { get; set; }
        public IEnumerable<Asset> Asset { get; set; }
        public IEnumerable<object> ModularContent { get; set; }
        public IEnumerable<TaxonomyTerm> Taxonomy { get; set; }
        public string UrlSlug { get; set; }
        public ContentItemSystemAttributes System { get; set; }
    }
}

How to use for Content Management SDK

Windows

CloudModelGenerator.exe --projectid "<projectid>" --contentmanagementapi [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--filenamesuffix "<suffix>"]

Linux, Mac OS and other platforms

dotnet run --projectid "<projectid>" --contentmanagementapi [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--filenamesuffix "<suffix>"]

Parameters

Parameter (single character variant) Keyword variant Required Default value Description
-p --projectid True null A GUID that can be found in Kentico Cloud -> API keys -> Project ID
-c --contentmanagementapi True false Indicates that models should be generated for Content Management SDK
-n --namespace False KenticoCloudModels A name of the C# namespace
-o --outputdir False \. An output folder path
-f --filenamesuffix False null Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs)
-b --baseclass False null If provided, a base class type will be created and all generated classes will derive from that base class via partial extender classes

These parameters can also be set via the appSettings.json file located in the same directory as the executable file. Command-line parameters always take precedence.

Example output

using System;
using System.Collections.Generic;
using KenticoCloud.ContentManagement.Models.Assets;
using KenticoCloud.ContentManagement.Models.Items;
using Newtonsoft.Json;

namespace KenticoCloudModels
{
    public partial class CompleteContentType
    {
        public string Text { get; set; }
        public string RichText { get; set; }
        public decimal? Number { get; set; }
        public IEnumerable<MultipleChoiceOptionIdentifier> MultipleChoice { get; set; }
        public DateTime? DateTime { get; set; }
        public IEnumerable<AssetIdentifier> Asset { get; set; }
        public IEnumerable<ContentItemIdentifier> ModularContent { get; set; }
        public IEnumerable<TaxonomyTermIdentifier> Taxonomy { get; set; }
        public string UrlSlug { get; set; }
    }
}

Feedback & Contributing

Check out the contributing page to see the best places to file issues, start discussions and begin contributing.

Wall of Fame

We would like to express our thanks to the following people who contributed and made the project possible:

Would you like to become a hero too? Pick an issue and send us a pull request!

Analytics