Skip to content

Read Only Property Support

Cy Scott edited this page Aug 22, 2021 · 3 revisions

If the interface has a get only property then it will be considered a read only property and a special constructor will be generated for initializing that read only property alone with all the other read only properties. Here is a simple example of how it works:

[Generate]
public interface IHaveAReadOnlyProperty
{
    Guid Id { get; }
}

The generated code will look like:

public class HaveAReadOnlyPropertyModel : IHaveAReadOnlyProperty
{
    public System.Guid Id
    {
        get
        {
            return _Id;
        }
    }
    private readonly System.Guid _Id;
        
    public HaveAReadOnlyPropertyModel(System.Guid Id)
    {
        _Id = Id;
    }
        
}

Clone this wiki locally