Skip to content

Commit

Permalink
Simplify DynamicMethod arg validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Oct 21, 2022
1 parent 50f7ab6 commit f5f8997
Showing 1 changed file with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,6 @@ public DynamicMethod(string name,
false);
}

// helpers for initialization

private static void CheckConsistency(MethodAttributes attributes, CallingConventions callingConvention)
{
// only public static for method attributes
if ((attributes & ~MethodAttributes.MemberAccessMask) != MethodAttributes.Static)
throw new NotSupportedException(SR.NotSupported_DynamicMethodFlags);
if ((attributes & MethodAttributes.MemberAccessMask) != MethodAttributes.Public)
throw new NotSupportedException(SR.NotSupported_DynamicMethodFlags);

// only standard or varargs supported
if (callingConvention != CallingConventions.Standard && callingConvention != CallingConventions.VarArgs)
throw new NotSupportedException(SR.NotSupported_DynamicMethodFlags);

// vararg is not supported at the moment
if (callingConvention == CallingConventions.VarArgs)
throw new NotSupportedException(SR.NotSupported_DynamicMethodFlags);
}

// We create a transparent assembly to host DynamicMethods. Since the assembly does not have any
// non-public fields (or any fields at all), it is a safe anonymous assembly to host DynamicMethods
private static Module GetDynamicMethodsModule()
Expand Down Expand Up @@ -242,7 +223,8 @@ private void Init(string name,
{
ArgumentNullException.ThrowIfNull(name);

CheckConsistency(attributes, callingConvention);
if (attributes != (MethodAttributes.Static | MethodAttributes.Public) || callingConvention != CallingConventions.Standard)
throw new NotSupportedException(SR.NotSupported_DynamicMethodFlags);

// check and store the signature
if (signature != null)
Expand Down

0 comments on commit f5f8997

Please sign in to comment.