none
Programmatically generate class files from dictionary/string RRS feed

  • Question

  • Hi, this is my first question here, and I might of missed some stuff regarding my issue.

    To get straight to the point, what I'm looking for is a way to create a .cs file with a custom class. 

    Now, to expand on this issue. What I'm working on is a form building tool, which allows you to create forms and once completed, the information will be saved to database. It's a small project for me to learn .net core, and C# in general (as this is the first time I'm using it). Until now, I got most of the stuff done, until I got to this part. Basically I want to create an EF Model, based on the form values programmatically (basically a .cs file, with a public class, with all the values from the dictionary (type/name) and once finished, just execute a command to migrate it). Once I do that, I also want to be able to create custom classes, based on those values/different checks.

    The only approach that comes to my mind at this point is actually to hardcore a text, where I'd replace values/names with dynamic data, but I'd leave the main structure (public class {class.name} {foreach ... {public data.type data.name;}}). Then save as a .cs file and after that, hope that the server would pick up the new class, or re-compile it (found somewhere a function on docs regarding compiling a file).

    This is a weird approach and I'm just wondering if anyone knows a more mainstream approach to this issue.

    Basically for each form, there will be a table with each column to represent the data type and data name of an input field, so once migrated and the form set online, all the data that's submitted there will go straight to the table.

    Thanks for the help!

    Monday, June 10, 2019 6:15 PM

All replies

  • IMHO, I don't see what you are talking about as viable, and you should abandon it. You should look into EF core scaffolding  and migration 

    https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx

    Basically for each form, there will be a table with each column to represent the data type and data name of an input field, so once migrated and the form set online, all the data that's submitted there will go straight to the table.

    Forms now of days whether it be  a Windows,  ASP.NET or WPF form  or ASP.NET MVC view based solution,  a UI design pattern is used and Seperation of Duty and Seperation of Concerns are applied. The  form is unaware of any table or database. The form is dumb as dumb as possible and is only concerned with UI controls and user inputs based on events such as control events or form events and all other logic is deferred elsewhere away from the form.

    https://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP

    https://en.wikipedia.org/wiki/Separation_of_concerns


    • Edited by DA924x Tuesday, June 11, 2019 9:28 AM
    Monday, June 10, 2019 7:26 PM