Dynamic codification is an expression to describe a functionality that is at this moment in development, it consists of giving auto-extension capabilities to a program through compilation of source code created at runtime by the destination machine, with this feature the application can auto-adapt to the execution environment, with this it can solve problems in programming that are not easily solved with tradicional programming methods that normally demands a lot of tedious work in developing and maintaining an application.
Some of these problems are known, for example the problem of the impedance between databases where these have a tabular structure and the objectos of a 4th generation programming language, for example C# or Java, that have a hierarchic structure with multiple levels, to compensate this problem the programmers make a lot of tedious work adapting one structure to the other, they can also use mapping libraries that demand a lot of work to configure them and maintain, this would be prevented if they had a library that reads the object class to persist, creating in runtime an object that extends the application object but with all the necessary methods to access the database in question, also being able to adapt to any database and also to any object, more details will be given in this study.
Creating applications that could adapt in runtime is a normal strategy to deal with scenarios that we couldn't determine in detail at the time of development, giving an open door to the introduction to a lot of lines of code in the future to compensate the lack of these scenarios at the time of application planning, however these problems are solved by creating code dynamically, thus compiling dynamic code while the application is in execution is an excellent way to compensate different machine configurations, users necessities, etc.
Dynamic coding is the execution of source code created and compiled in execution time with templates predetermined by the programmer at time of development, also called by snippets, this is a very powerful functionality that allows the applications to be extended with code that is not compiled with the application at time of development, instead it is compiled by the application at runtime using guides created by the programmer.
To be obtained this in an application, for example on Windows programming environment we had in the past and also in the present day, however less used, the resource of VBScript code interpreted on Windows script engine, we also have VBA that is an implementation of the Visual Basic for MS Office products, inside of all this type of solutions we have the advantage to add functionalities to applications, however these solutions have a great disadvantage that is the need to be interpreted in runtime and not compiled, resulting in a great impact on performance, and also the debug system is very precarious.
If there exists so many disadvantages with these solutions why did we think to use them? They will not be used exactly because these solutions have the disadvantages cited before, however the great advantage above related was not forgotten, quite to the contrary it was rethink and incorporated in a functionality of the .NET Framework.
.Net Framework of Microsoft implements in its classes of SDK all the functionalities necessary to natively provide total control on dynamic code, however this process is not very trivial requiring a certain amount of operations necessary to obtain themselves to compile and to execute dynamic code previously written in source code C# or VB.NET, but the great advantage is that we can use this code directamente in our application also being able to keep later to use, for moreover all gets an extreme flexibility having total control on the compilation process, management of errors of compilation, loading of objects and control on the execution environment of the dynamic code.
To approach this project we go to divide it into small pieces of the problem, the first one will be about compiling source code dynamically in our applications, for this we go to create a source code file in C# code and another one in VB.NET having both the same functionality, after that we will compile the code in runtime, to be able to use this parcel of the problem in the next ones we go to make a reusable class that encapsulates all the details of the compilation and execution of the dynamic code.
In the second piece will be introduced an optimization to the compilation process, therefore in case that a source code equals to one already compiled in the past then the old one is used avoiding the all compilation process, for this it is used an SQLite database to store an hash code of the source code, source code and compiled assembly, so if in a later time the same hash is found comparing the source code hashes and if they are equal then will be used the binary already compiled, with this the source code compilation is optimized to very frequent code.
In the third piece of the development we will develop a small system of script development, giving information on the compiling errors and execution.
