Record

The Record aspect can be used in any language to mark a class as following the C# 9.0 "Record" design paradigm.

C# Records are special classes (and not to be confused with Records in Oxygene, which are what is calle structs in most other languages) that automatically get additional behavior injected by the compiler.

From Microsoft's documentation:

Records are distinct from classes in that record types use value-based equality. Two variables of a record type are equal if the record type definitions are identical, and if for every field, the values in both records are equal. ... Value-based equality implies other capabilities you'll probably want in record types. The compiler generates many of those members when you declare a record instead of a class.

In C# and Mercury, you can use the record/Record keyword, replacing class/Class in the declaration, to mark a class as record. In all languages (except Go, which does not offer classes at all), you can use the Record aspect to achieve the same).

Records can only descend from classes also marked as record (or the base Object, of course), and any classes that descend from a record must also be marked as record.

[&Record]
type
  Foo = public class(Bar)
  public
    property Name: String;
  end;
[Record]
public class Foo : Bar
{
    public string Name { get; set; }
}
@Record
public class Foo : Bar {
    public var Name: String
}
@Record
public class Foo : Bar {
    public string Name { get; set; }
}
<[Record]>
Public Class Foo 
  Inherits Bar

  Public Property Name As String
  
End Class

Equivalent using the keyword

public record Foo : Bar
{
    public string Name { get; set; }
}
Public Record Foo 
  Inherits Bar

  Public Property Name As String
  
End Record

See Also