Skip visibility checks for dynamically generated methods without DynamicMethod #48024
-
There are similar questions about this topic ob StackOverflow already see: first, second, third and fourth. However I also want to bring up the discussion here. The essence of the question really is, "How do you ignore accessibility restrictions through the TypeBuilder/MethodBuilder API's". Here is an example of this problem. There are few other questions which raise for me.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
You can bypass access checks using Here's a modified version of your fiddle which includes the attribute: https://dotnetfiddle.net/YPkT7H As an aside, if that fiddle is the main motivation for you doing this you should look at |
Beta Was this translation helpful? Give feedback.
You can bypass access checks using
IgnoresAccessChecksToAttribute
. The runtime understands the attribute, but it is not defined in the BCL so you have to define it yourself.Here's a modified version of your fiddle which includes the attribute: https://dotnetfiddle.net/YPkT7H
As an aside, if that fiddle is the main motivation for you doing this you should look at
CollectionsMarshal.AsSpan
.