Skip to content
New issue

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

Simplify DynamicMethod arg validation #77277

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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