- Home /
Extract C# code from XML file
Is there any way to extract a C# function definition from an XML file at run-time.
At run-time, the game loads information from XML files and initializes the scene and UI based on the info from the files. Our team is using external tools to design a UI layout and the tool stores the layout in an XML file including custom defined C# function to run when a button is pressed. I need to figure out a way to load and/or evaluate the code from the XML file generated by the external tool.
I am using the Unity Pro license so I have access to all MonoDevelop functionality.
Answer by amirabiri · Jun 15, 2012 at 03:24 PM
Microsoft's C# does not yet have a "compiler as a service", i.e simple ability to compile code from code (It's coming soon but isn't available yet). However Mono's implementation of C# does have that, which is part of why Unity uses C# to begin with.
Unfortunately when Unity builds the C# VS project for you, they don't use the mono runtime. I don't know what happens on the MonoDevelop side as I don't use it. Either way, the relevant namespaces may not be exposed to the project.
Best thing to do is read about Mono's "compiler as a service" capabilities and try to add it as a manual reference to the project and see what happens. It is very likely that the namespace will be available at runtime (Since Unity use it internally) just not exposed to the project.
Should also point out that this isn't going to work on iOS unless you have the function compiled ahead of time.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072825im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Flip over an object (smooth transition) 3 Answers