CodeDom Generate Unsafe Code OR Alternate Compilation Alternatives
I just got done developing a fairly large project using CodeDom. Well, almost done - exept for one small issue - One开发者_StackOverflow中文版 of the classes in my project requires the /unsafe
tag. I have read that CodeDom does not support the *generation *of a method or type with the unsafe pointer, however, I was curious as to whether or not there was some way I could compile a class from a file - that already has the unsafe tag incorporated. I know that I can manually create a .csproj file and enable unsafe code from here, but again, I do not think that I can use this .csproj file when compiling from file(s).
Lastly, if none of the above methods are possible, is there some way I could use a C#.dll to generate source code? Perhaps the same one that VS is using by default.
Thank you for the help!
Evan
You can generate methods in codedom with unsafe pointers, through the usage of the CodeSnippetTypeMember class.
What you can't do is Generate methods with unsafe pointer in a portable fashion because CodeDom only has a subset of the features the languages are capable of. The features you find in codedom are the ones that are more likely to be present in many languages.
As for your question; you should be able to compile a class from a file. Create a CompilerParameters object similare to this one.
CompilerParameters cp = new CompilerParameters();
cp.CompilerOptions = "/unsafe";
and then invoke CompileAssemblyFromFile on your chosen provider
精彩评论