Marcel Lamothe
Marcel Lamothe

Reputation: 12912

What is the point of the MethodImplAttributes.MaxMethodImplVal value?

The description in MSDN for MethodImplAttributes.MaxMethodImplVal:

Specifies a range check value.

That's about all I could find on it. But what is this actually used for?

Upvotes: 0

Views: 38

Answers (2)

Jeff Mercado
Jeff Mercado

Reputation: 134491

It's just a special value that allows for simpler range checking for valid values. Any value whose integral value is greater than this value can be considered invalid. Remember, although enumerations define names for certain values, it doesn't mean that values that doesn't correspond to a single enumeration is invalid. This is especially true for Flags.

You would see it often used like this:

void Foo(MethodImplAttributes attrs)
{
    if (attrs < 0 || attrs > MethodImplAttributes.MaxMethodImplVal)
        throw new ArgumentOutOfRangeException("attrs");
    // do stuff
}

For the range of valid values, what's actually in use is sparse. It would be impractical to test for every possible valid value, even more so the invalid ones. This check however eliminates more of the obvious invalid values. Then code would just have to deal with or ignore the rest.

Judging by the values and comments and how they're arranged in source, it looks like the enumeration has multiple uses so this check is almost a necessity.

Upvotes: 1

Ron Beyer
Ron Beyer

Reputation: 11273

As far as I can tell, ts not meant to be used, it simply the largest value for the MethodImplOptions enumeration.

Upvotes: 0

Related Questions