From 6e9fe5093dc1a95c386bc1d385eecc2c43e79fc3 Mon Sep 17 00:00:00 2001 From: Tim Van Holder Date: Sat, 17 Aug 2024 16:26:00 +0200 Subject: [PATCH] Add the "allow byref-like" anti-constraint 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. --- Mono.Cecil/GenericParameter.cs | 10 ++++++++++ Mono.Cecil/GenericParameterAttributes.cs | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Mono.Cecil/GenericParameter.cs b/Mono.Cecil/GenericParameter.cs index 30dd73382..838646c08 100644 --- a/Mono.Cecil/GenericParameter.cs +++ b/Mono.Cecil/GenericParameter.cs @@ -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); } @@ -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) diff --git a/Mono.Cecil/GenericParameterAttributes.cs b/Mono.Cecil/GenericParameterAttributes.cs index 149582cdb..3c2f0afd1 100644 --- a/Mono.Cecil/GenericParameterAttributes.cs +++ b/Mono.Cecil/GenericParameterAttributes.cs @@ -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, } }