vendredi 3 septembre 2021

Getting the primary constructor of a C# record

Consider the following C# record, which has one primary constructor and one secondary constructor:

record Foo(string Text, int Number)
{
    public Foo() : this(string.Empty, default)
    {
    }
}

Getting its constructors can be achieved like so:

ConstructorInfo[] constructors = typeof(Foo).GetConstructors();

Is there a way to determine which constructor is the primary constructor?





Aucun commentaire:

Enregistrer un commentaire