DIVEX

Getting Started

To get started with DIVEX, you need to install it from https://divex.dev/download. Once you receive a download link and download the DIVEX VSIX file, double click on it. This will start the installer. Review the license agreement and then proceed with the installation. Note that DIVEX requires Visual Studio 2019.

Once DIVEX is installed, create a new application project, e.g. a Console Application. To use DIVEX in that project, you need to install the DIVEX.Core nuget package.

Now, do the following in Program.cs:

  1. Decorate the Program class with the DIVEX.Core.DivexCompose attribute.
  2. Make the Program class public and partial.
  3. Add a using static directive for DIVEX.Core.DivexUtils. (Required for some features).
using System;
using DIVEX.Core;
using static DIVEX.Core.DivexUtils;

namespace SampleApplication
{
    [DivexCompose]
    public partial class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

The above code shows the three steps applied. Now, we are ready to use DIVEX’s features. Now, create the following class:

public class Greeter
{
    private readonly string greeting;
    private readonly bool includeExclamation;

    public Greeter(string greeting, bool includeExclamation)
    {
        this.greeting = greeting;
        this.includeExclamation = includeExclamation;
    }

    public void Greet(string personName)
    {
        var message = 
            greeting
            + " " + personName
            + (includeExclamation ? "!" : "");

        Console.WriteLine(message);
    }
}

And then change the Main method of the Program class to use DIVEX like this:

[DivexCompose]
public partial class Program
{
    static void Main(string[] args)
    {
        var createGreeter = CtorOf<Greeter>()
            .Apply(includeExclamation: true);

        var greeter1 = createGreeter.Invoke(greeting: "Hello");

        var greeter2 = createGreeter.Invoke(greeting: "Hey");

        greeter1.Greet("Adam");

        greeter2.Greet("Sam");
    }
}

And now save. Once you save, DIVEX will generate code to make this code work.

For more information about what DIVEX is, see the Introduction to DIVEX article.
For more details about the types of functions DIVEX supports, see DIVEX functions.
For more details about the operators that DIVEX supports, see DIVEX operators.