Providing Custom Constructors

You can set the [HasCustomConstructor] property on a domain class to true to indicate that you are providing one or more custom constructors. When you use a custom constructor, you define how the constructor is initialized.

Custom Constructors Example

The following example references a real-world domain model, Library.dsl, to define a custom constructor for a domain class called [CirculationBook]. To add custom constructors, you create a partial class, define one or more constructors in it, and then add the partial class to the project.

The [CirculationBook] domain class has the GeneratesDoubleDerived property set to true. Therefore, you must define custom constructors for both the [CirculationBook]class and the[CirculationBookBase] abstract base class.

using Microsoft.VisualStudio.Modeling;

namespace ExampleNamespace
{
    public partial class CirculationBookBase
    {
        public CirculationBookBase(Partition partition, PropertyAssignment[] propertyAssignments) : base(partition, propertyAssignments)
        {
        }
    }
    public partial class CirculationBook
    {
        public CirculationBook(Partition partition, PropertyAssignment[] propertyAssignments) : base(partition, propertyAssignments)
        {
        }
    }
}

See Also

Concepts

Overview of Library.dsl

Domain-Specific Language Tools Glossary

Reference

Partition

PropertyAssignment