# SourceGenerators - Introduction

Xenial. Framework's SourceGenerators helps you to create more robust compile time safe code and remove a lot of boilerplate code that you otherwise may write by hand.

Most of them reflect on your business model code and can increase performance and reliability of otherwise reflection based lookups.

SourceGenerators are one of the many NonVisual Components of Xenial.Framework designed to promote best practice and efficient working in large teams, which in turn are equally applicable to smaller teams and projects and even individuals working on a single application.

# Installation

In your platform agnostic module (opens new window) install the Xenial.Framework.SourceGenerators (opens new window) package.

INFORMATION

By convention the platform agnostic module is usually named <Your Application>.Module. If you're unfamiliar with the Command Line Interface (cli) you can always use the Nuget package manager.

Whilst the Xenial.Framework can of course be used in platform specific modules, for the purposes of this documentation emphasis will be given to its use in the platform agnostic module of your project.

TIP

If you use VisualStudio make sure you at least are using 2019 v16.9 or higher (opens new window). According to our tests VisualStudio 2022 or higher is recommended. You also need to install the .NET5 SDK (or greater) (opens new window) even if you want to use generators with net462 (Full Framework)

# Overview

There are a bunch of generators designed to tackle particular problems when developing a larger XAF source base. Because they are compile time features they may not reflect 100% runtime behavior, but are designed to be as close as possible. Most of the generators focus on reliability and make it possible to create compile time safe, intellisense driven, faster XAF development cycle. Because we are inspecting source code, each generator has pro's and con's but most con's lay on the reflective nature of XAF.

  1. ViewIdsGenerator - Emit view id constants based on your XAF model
  2. ImageNamesGenerator - Emit image name constants and access resources statically
  3. XpoBuilderGenerator - Emit a builder pattern for creating XPO and non persistent objects
  4. LayoutBuilderGenerator - Emit strongly typed code to help use DetailViewLayoutBuilders without reflection
  5. ColumnsBuilderGenerator - Emit strongly typed code to help use ListViewColumnsLayoutBuilders without reflection
  6. ModelBuilderGenerator (CTP) - Emit strongly typed code to help use ModelBuilders without reflection
  7. ActionGenerator (CTP) - Emit controllers and actions in a command pattern style

All of the generators are designed to work together in harmony, however because of their technical nature they depend on execution order like here listed order to work correctly.

INFORMATION

This list may not be 100% technical accurate and complete, but will focus on the usage side.

To see a full list you should check out the Appendix section

# SourceGenerators are patterns that evolve with your code

Because each generator tries to solve a runtime the documentation will try to follow a pattern like described by Martin Fowler (opens new window) which will be structured in the following sections:

  • Intent - Why this generator exists
  • Usage - What you need to implement
  • Generated-Code - What is the outcome based on a sample
  • Advantage - Why this is helpful
  • Drawbacks/Issues - What limitations the generator has
  • API-surface - What API's/Attributes are involved when using this generator
  • Options - Often source generators have additional options that change the shape of the generated code to help with very large code bases
  • Diagnostics - What diagnostics the generator emits when a wrong usage is detected

TIP

There are a lot of Features that are enhanced when using SourceGenerators we highly recommend to use them as a best practice. However all features are designed to be usable without them. If you encounter a problem when using other features without the use of SourceGenerators let us know (opens new window)!