Skip to content

Commit

Permalink
Add the "allow byref-like" anti-constraint
Browse files Browse the repository at this point in the history
This adds a new `AllowsByRefLike` flag to `GenericParameterAttributes`
which, unlike the others, is an anti-constraint (i.e. it removes
restrictions rather than adding them) added in C# 13.
Because of this, `AllowsByRefLike` was chosen as the corresponding bool
property on `GenericParameter` (instead of
`HasAllowByRefLineConstraint`; the constant also does not include
`Constraint` in its name).

At the same time, it adds the `NoSpecialConstraint` flag and a
corresponding `HasNoSpecialConstraint` property.
  • Loading branch information
Zastai committed Aug 17, 2024
1 parent 56d4409 commit 6e9fe50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Mono.Cecil/GenericParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public bool IsContravariant {
set { attributes = attributes.SetMaskedAttributes ((ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Contravariant, value); }
}

public bool HasNoSpecialConstraint {
get { return attributes.GetMaskedAttributes ((ushort) GenericParameterAttributes.SpecialConstraintMask, (ushort) GenericParameterAttributes.NoSpecialConstraint); }
set { attributes = attributes.SetMaskedAttributes ((ushort) GenericParameterAttributes.SpecialConstraintMask, (ushort) GenericParameterAttributes.NoSpecialConstraint, value); }
}

public bool HasReferenceTypeConstraint {
get { return attributes.GetAttributes ((ushort) GenericParameterAttributes.ReferenceTypeConstraint); }
set { attributes = attributes.SetAttributes ((ushort) GenericParameterAttributes.ReferenceTypeConstraint, value); }
Expand All @@ -165,6 +170,11 @@ public bool HasDefaultConstructorConstraint {
set { attributes = attributes.SetAttributes ((ushort) GenericParameterAttributes.DefaultConstructorConstraint, value); }
}

public bool AllowsByRefLike {
get { return attributes.GetAttributes ((ushort) GenericParameterAttributes.AllowByRefLike); }
set { attributes = attributes.SetAttributes ((ushort) GenericParameterAttributes.AllowByRefLike, value); }
}

#endregion

public GenericParameter (IGenericParameterProvider owner)
Expand Down
6 changes: 4 additions & 2 deletions Mono.Cecil/GenericParameterAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public enum GenericParameterAttributes : ushort {
Covariant = 0x0001,
Contravariant = 0x0002,

SpecialConstraintMask = 0x001c,
SpecialConstraintMask = 0x003c,
NoSpecialConstraint = 0x0000,
ReferenceTypeConstraint = 0x0004,
NotNullableValueTypeConstraint = 0x0008,
DefaultConstructorConstraint = 0x0010
DefaultConstructorConstraint = 0x0010,
AllowByRefLike = 0x0020,
}
}

0 comments on commit 6e9fe50

Please sign in to comment.