.net - Compiling C# unsafe code -
i have small c# class few unsafe methods. there way specify "/unsafe" option declaratively in c# source code (with #pragma
or anyhow else) context of class' source file? i'd hate create separate assembly such small class, don't want rest of assembly (the class part of) enabled unsafe code.
no, (currently) not possible, entire assembly affected having unsafe code in it.
by including unsafe code in assembly, telling clr assembly something, well, unsafe, changes how runtime acts when loads assembly. biggest change here clr not try verify unsafe code, refuse load assembly unless has full-trust (e.g. couldn't load unsafe assembly normal user on click-once.)
from technical perspective, when use /unsafe
option, causes compiler emit il equivalent of following module-level attributes assembly:
[assembly:securitypermission(skipverification = true)] [assembly:unverifiablecode]
your best option is, said, isolate unsafe code own separate assembly as possible. fact assembly has 1 class in less of code-smell tainting entire assembly full of safe code due 1 unsafe class.
Comments
Post a Comment