---
title: Generating classes for Kentico objects
related:
  - https://docs.kentico.com/k9/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/retrieving-content-on-mvc-sites.md
  - https://docs.kentico.com/k9/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/working-with-page-attachments-in-mvc-applications.md
  - https://docs.kentico.com/k9/custom-development/working-with-pages-in-the-api.md
  - https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/page-types.md
  - https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/custom-tables.md
  - https://docs.kentico.com/k9/managing-website-content/forms.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

This page describes how to use code generators to prepare wrapper classes for working with specific object types ([Page types](https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/page-types.md), [Custom tables](https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/custom-tables.md) and [Forms](https://docs.kentico.com/k9/managing-website-content/forms.md)).

Code generators are available for the following objects, in their respective applications:

- [Page types](https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/page-types.md) - allow you to generate a class with the page type's fields as properties and a provider to retrieve the individual pages.
  - [Generate code for individual page types](#generating-code-for-a-specific-page-type) on the **Code** tab of the specific types.
  - [Generate code for all site page types](#generating-code-for-all-site-page-types) on the **Code** tab of the **Page**  **types** application.
- [Custom tables](https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/custom-tables.md) - allow you to generate a class with the custom table's fields as properties.
  - Generate code for individual custom tables on the **Code** tab of the specific custom tables.
- [Forms](https://docs.kentico.com/k9/managing-website-content/forms.md) -  allow you to generate class with the form's fields as properties.
  - Generate code for individual forms on the **Code** tab of the specific forms.

Code generators allow you to create classes for working with specific objects types (Page types, Custom tables, Forms) in the API.

## Working with page type code generators

The page type code generators allow you to generate both properties and providers for your custom page types. The generated properties represent the page type fields. You can use the providers to work with published or latest versions of a specific page type.

### Generating code for all site page types

1. In the **Page types** application, navigate to the **Code** tab.
2. Select a **Site**.
3. (Optional) Select a different default folder to place the code files in.
4. (Optional) If you want to generate code for [container page types](https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/page-types/creating-container-page-types.md), enable **Include container page types**.
5. **Save code**.

   > **Info:** **Note**: The generated class names are not guaranteed to be unique. The system can in certain cases (usually when also generating code for container page types) generate multiple classes with the same name. In that case, you need to rename the classes manually.
6. Copy the generated code files to your MVC application project. By default, the generated code files are stored in _\~/App\_Code/CMSClasses_ folder of your Kentico project.
7. If you want to use the code files in a separate library or external application, allow the system to detect the generated classes in a custom assembly. Add the 'AssemblyDiscoverable' assembly attribute in the library/application  project's _AssemblyInfo.cs_ file:

   ```csharp

   using CMS;
   ...
   [assembly: AssemblyDiscoverable] 

   ```
8. Use the generated properties in your code.
9. Build your MVC application solution.

### Generating code for a specific page type

1. Create a custom [Page type](https://docs.kentico.com/k9/developing-websites/defining-website-content-structure/page-types.md).
2. In the **Page types** application, navigate to the page type's **Code** tab.
3. **Save code**.
4. If you want to use the code files in a separate library or external application , allow the system to detect the generated classes in a custom assembly. Add the 'AssemblyDiscoverable' assembly attribute in the library/application  project's _AssemblyInfo.cs_ file:

   ```csharp

   using CMS;
   ...
   [assembly: AssemblyDiscoverable] 

   ```
5. Use the generated properties in your code.
6. Build your solution.

## Customizing generated classes

We do **not recommended modifying the generated classes** as they contain object properties only.

The classes are generated as _partial classes_. This means that you can extend them in a separate code file. Using this approach, you avoid the need to merge custom changes made to the generated code every time the class is generated again after the object's properties are changed.

### Example of customizing generated classes

```csharp title="Articles.generated.cs - generated class"

namespace CMS.DocumentEngine.Types
{
    public partial class Article : TreeNode
    {
        ...

        /// <summary>
        /// Article name.
        /// </summary>
        [DatabaseField]
        public string ArticleTitle
        {
            get
            {
                return ValidationHelper.GetString(GetValue("ArticleTitle"), "");
            }
            set
            {
                SetValue("ArticleTitle", value);
            }
        }
        ...
    }
}

```

```csharp title="Articles.cs - extending the generated class"

namespace CMS.DocumentEngine.Types
{
    /// <summary>
    /// Custom article page type class.
    /// </summary>
    public partial class Article : TreeNode
    {
        /// <summary>
        /// Loads sample data into this object.
        /// </summary>
        public void LoadSampleData()
        {
            ArticleTitle = "Sample article title";
            ArticleSummary = "Sample article summary";
            ArticleText = "Sample article text";
        }
    }
}

```
