Generate C# Class Library project programatically with given fields [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to create a module that will generate class library project from given database columns that will include info class,dataprovider class and contorller class each having their own .cs file. What i have done now is that create info,provider and controller class.
I have researched to create class library project programatically but still not much success..What i want to do is create a class library project programatically and move those files to the project folder.After that compile the library project and generate dll file and move that to bin folder of website.
Can anyone please point me to the right direction or give some useful resources so that i can use that to solve my problem.

I would use a T4 template and then you can programatically emit a C# class based on your database structure.
https://msdn.microsoft.com/en-us/library/bb126445.aspx

I have used the T4 template and it is very useful for same type of code generation. We can have XML for configuration (class and properties) and then automatically we can create classes for them. They are useful since the same configuration can be used for database layer, mapping properties to database fields etc. so your back-end layers can be automated.
Note: All classes should have common design. Also make class as partial so that you can always add more functionality to it.

Related

What do you call this approach on ASP.net Core MVC? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm new to ASP.NET Core MVC , and I'm watching a lot of courses and tutorials about it but the current project that I'm working with, is a little different from what I have learned through tutotials and courses.
On my project solution I have a folder containing classes.
And on that classes contains Entity Class,Constructor,Factory Methods,CriteriaInfo Class and Data Access and also each class extends into an Assemblies.
Is this approach is MVC but using a class library ? Because the model I think is in the class because I'm not seeing any model on my Model folder(except for the defaults).
if you are using visual studio then it will create a default mvc project on users request, and there will probably no folders for models, if you want you can put these models to a folder or into another project as a class library. All these changes are upto the developer concern.
Class library is nothing but just a another namesapce, where we can save the files and can be use to multiple project if the dev wants to
you can find the type class library when you search in studio
the only thing is to select the appropriate type for your project. It will gives you the basic template just like you created the mvc project. you can edit upon the template
official documentation
https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?view=aspnetcore-5.0&tabs=visual-studio
good tutorial
https://dotnettutorials.net/course/asp-net-core-tutorials/

Where should interfaces go in C# layered app [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm building a C# WPF app that will use IBM iSeries data for starters but will use oracle data via web service later. In order to switch between them (and support testing) we create interfaces and program the view to interface, right? Each of the data sources would be responsible for mapping to a common DTO structure used in the view model.
So if these two data sources that implement the interfaces are in separate projects, where are the interfaces defined? I'm thinking about how to define the interfaces so I don't have to keep up separate versions in the respective data source projects. If I create the interfaces in the view then it would create circular reference, the data source needing the view for the interfaces and the view needing the data source for dependency injection.
Please forgive me for the rather generic question. I'm not asking "how do I structure my app", it's more of how do I solve the specific issue of the mechanics of the interfaces.
Thanks, Mike
Put them in a separate project. Add a reference to that project wherever you want to use them.

Recreating ASP.NET MVC website from source files [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
my client has had his website developed in ASP.NET C#. Since then the developer closed down and now he needs to re-host his website on different server.
The website is split into two parts: admin panel and main pages. each folder contains bin, Views, Assets subfolders, web.config files and Global.asax file. The website uses Entity Framework but there are no database files whatsoever and web.config files need to be added. Is it possible to somehow reverse engineer the source code to create needed databases along with all the required tables?
Although it can be a daunting task, you can decompile .net binaries with the following tool: http://ilspy.net/
If EntityFramework code first was used, you can restore the database using entity framework migrations. See the last part of this article:
https://msdn.microsoft.com/en-us/library/jj193542(v=vs.113).aspx
In addition to ilspy I'd recommend looking at JetBrains dotPeek. I've used it to recover source code for a couple of my projects from back before I was using a proper source control.
One thing to be aware of when using a decompiler is that you're going to get the actual code produced, not the original source. The things that we call 'syntactic sugar' will look completely different when decompiled. Some of them might come out so mangled that you won't get them to compile.

how to use xml in C# : xml newbie [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a program in C#,and I want to use xml in it.
I am very new to XML,I have a fairly large configuration data with lots of fields.I have managed to define a class based on my configuration fields,my class has lot of enums ,lists and user defined types.
Now I want to read/edit/modify/save the values in configuration,I am thinking of using an xml file.
Can you give me some direction.Should I define a xml schema? What should be the design of my program? Or please suggest how to do this fast and clean through existing APIs like LINQ etc.
In a nut shell
Can you explain
How to save class with lot of fields to XML through C#?
Do I need a schema?
How to read it back in same class and validate through schema?
Approach should be simple and unit testable.
You can use the XSD.exe tool to create a schema from your XML and generate a serializable class. Then you can populate the class instance in your code and serialize it out to XML, or deserialize the XML back into a class instance.
Search with a phrase something like 'serializable class with xsd.exe' and you will find plenty of tutorials.
Of course, there are newer and better ways if you just want to persist application configuration.
example

How can I effectively manage class libraries that reference each other? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am going to be creating a web application for internal company use. I created one "General.dll" class library that contains abstract classes such as Person, EmailAddress, etc. And then I created an "EmployeeManagement.dll" which includes classes such as Employee : Person, EmployeeEmailAddress : EmailAddress, etc.
My EmployeeManagement.dll references and relies on General.dll.
Then my web application will reference EmployeeManagement.dll.
How can I effectively keep track of cascading changes? For example, if I make a change to General.dll, I will need to recompile that class library into a new General.dll, and then remember to reference the new General.dll in every other class library that uses it. Then those libraries will need to be recompiled and I have to remember to update the references in the web application to those as well...Seems like there must be a tool or more efficient way to handle this that I just don't know of. Any tips?
For a start, if you add all of your projects to the same solution in Visual Studio then they will automatically be rebuilt as appropriate based on dependencies when you make a change.
Also, during development you probably don't want to add a reference to a particular version of an assembly (this is the default when choosing 'Add reference'). In this way, any changes to your General.dll will automatically cascade to any other project that references it on the next build.
Edit after update from OP
You are quite free to reuse projects in different solutions. So you can have exactly one codebase for General.dll and include that project in any solution that needs it. In that case you of course need to be careful when making changes to General.dll to avoid potentially breaking any project that includes it (a continuous integration utility can help here).

Categories

Resources