We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ILSpy should output the short record R(int a, int b); syntax where possible.
record R(int a, int b);
Example records:
record R(int A) { public int B; public int C { get; set; } } record Derived(int X) : R(X * 2);
Generated unless user-declared.
// R: protected virtual Type EqualityContract { [CompilerGenerated] get { return typeof(R); } } // Derived: protected override Type EqualityContract { [CompilerGenerated] get { return typeof(Derived); } }
protected R(R original) { b = original.b; C = original.C; } protected Derived(Derived original) : base(original) { X = original.X; }
Always generated; cannot be named in user code.
public virtual R <Clone>$() { return new R(this); } public override R <Clone>$() { return new Derived(this); }
Equals(object?) overload: always generated; error if also user-declared. Equals(R?) overload: generated unless user-declared.
Equals(object?)
Equals(R?)
// R public override bool Equals(object? obj) { return Equals(obj as R); } public virtual bool Equals(R? other) { return (object)other != null && EqualityContract == other.EqualityContract && EqualityComparer<int>.Default.Equals(A, other.A) && EqualityComparer<int>.Default.Equals(B, other.B) && EqualityComparer<int>.Default.Equals(C, other.C); } // Derived public override bool Equals(object? obj) { return Equals(obj as Derived); } public sealed override bool Equals(R? other) { return Equals((object?)other); } public virtual bool Equals(Derived? other) { return base.Equals(other) && EqualityComparer<int>.Default.Equals(X, other!.X); }
// R: public override int GetHashCode() { return ((EqualityComparer<Type>.Default.GetHashCode(EqualityContract) * -1521134295 + EqualityComparer<int>.Default.GetHashCode(A)) * -1521134295 + EqualityComparer<int>.Default.GetHashCode(B)) * -1521134295 + EqualityComparer<int>.Default.GetHashCode(C); } // Derived: public override int GetHashCode() { return base.GetHashCode() * -1521134295 + EqualityComparer<int>.Default.GetHashCode(X); }
Always generated; error if also user-declared.
public static bool operator ==(R? r1, R? r2) { return (object)r1 == r2 || (r1?.Equals(r2) ?? false); } public static bool operator !=(R? r1, R? r2) { return !(r1 == r2); } public static bool operator ==(Derived? r1, Derived? r2) { return (object)r1 == r2 || (r1?.Equals(r2) ?? false); } public static bool operator !=(Derived? r1, Derived? r2) { return !(r1 == r2); }
Generated if not user-declared.
public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("R"); stringBuilder.Append(" { "); if (PrintMembers(stringBuilder)) { stringBuilder.Append(" "); } stringBuilder.Append("}"); return stringBuilder.ToString(); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("Derived"); stringBuilder.Append(" { "); if (PrintMembers(stringBuilder)) { stringBuilder.Append(" "); } stringBuilder.Append("}"); return stringBuilder.ToString(); }
// R: protected virtual bool PrintMembers(StringBuilder builder) { builder.Append("A"); builder.Append(" = "); builder.Append(A.ToString()); builder.Append(", "); builder.Append("B"); builder.Append(" = "); builder.Append(B.ToString()); builder.Append(", "); builder.Append("C"); builder.Append(" = "); builder.Append(C.ToString()); return true; } // Derived: protected override bool PrintMembers(StringBuilder builder) { if (base.PrintMembers(builder)) { builder.Append(", "); } builder.Append("X"); builder.Append(" = "); builder.Append(X.ToString()); return true; }
Generated only for positional records. Error if also user-declared.
public R(int A) { this.A = A; base..ctor(); } public Derived(int X) { this.X = X; base..ctor(X * 2); }
public void Deconstruct(out int A) { A = this.A; } public new void Deconstruct(out int X) { X = this.X; }
The text was updated successfully, but these errors were encountered:
For the decompiler this means:
operator==
operator!=
Equals(object)
Equals
GetHashCode
PrintMembers
Sorry, something went wrong.
Still missing:
class
record
No branches or pull requests
ILSpy should output the short
record R(int a, int b);
syntax where possible.Compiler-generated members in records
Example records:
EqualityContract
Generated unless user-declared.
Copy Constructor
Generated unless user-declared.
Clone method
Always generated; cannot be named in user code.
Equals methods
Equals(object?)
overload: always generated; error if also user-declared.Equals(R?)
overload: generated unless user-declared.GetHashCode
Generated unless user-declared.
operator==
Always generated; error if also user-declared.
ToString
Generated if not user-declared.
PrintMembers
Generated if not user-declared.
Primary Constructor
Generated only for positional records. Error if also user-declared.
Deconstruct
Generated only for positional records. Error if also user-declared.
The text was updated successfully, but these errors were encountered: