C# Class Diagram Dynamic Updating - c#

I have a class diagram in C# and to test it out I'd like to use it to generate code and then go back and edit it. So I need to be able to go back and forth, generate code, update class diagram, rinse repeat.
However, for some reason I was only able to generate code once. If I try to generate code again it says "another project might exist in the same solution". How can I get around this?
Also when I update the generated code I'd like it to update the class diagram. Is that possible?
Thank you.

The difference is a .cd vs a .classdiagram. The .classdiagram does not update dynamically. The .cd or "logical class designer" does.

Related

Wondering if we could generate code with T4 Template on a builded solution

I'm trying to figure out if we could generate code with a T4 Template file post-build.
In fact, I'm kinda new to c# and I needed to find a solution where I generate class from Xml file that could be edited by the user at anytime and the first solution that come to me is T4 Template.
Then I render those generated classes on a treeView and the according properties on a property grid.
Now, I think that it is only generate code at pre-build time, but I'm not sure about that since I don't really see a lot of stuff about that on the internet. I'm still pretty sure now that it's not possible.
So, a second problem comes to me : I finished my entire project like that, so if you all have an idea or another solution that could be nice, i'll really appreciate that.
The 'T4Executer' extension has an option to attach the execution of each T4 template to build events. Before, during and after build, or not run them at all.
Doesn't work for Visual Studio 2022 yet though.

Saving history from a SQL database using C#

I don't think I need to post any code but if I need to I will.
I have created a Windows Form in Visual Studio that creates a record and saves it into a database. I have also added an update function so that I can change the record and save the new changes.
What I need to know though is how to create some kind of version history. i.e. When I click update, I want it to save the previous version so that I can look back at it. Like a bug tracker has a kind of version control but a lot simpler (hopefully).
Would I need a separate database? Could I have another datagridview that when a record is clicked on (or a button) it will show the history of changes for that record?
I've done many searches online and just can't find how to do it or where to look exactly to find this?
Any help would be greatly appreciated.
Thanks
you are talking about audit trail , take look at this :Link
I know this example for MVC but it's the same idea
you only need one table to track changes of the whole database by using json objects that represent "before" and "after"

Updating the namespace automatically in Visual Studio 2015/ C#

I am doing some clean up/ restructuring on my code (C#) were I move my classes in the tree structure. I am looking for a way to update all namespaces to the default ones (like projectname.rootFolder.ChildFolder).
I know that there are some ways to do it one by one like in this old post but I am looking for a clean simple update way. I wish there was something like "right clicking on the folder and clicking on update namespace!" but there is not.
Anyone knows any add-on/ easy way to do it?
Resharper is a tool to work on legacy code. Try to use this tool.
Right click on the folder> go to refactor and then select adjust Namespaces

What is the name for code automation or automatic code insertion on Visual Studio?

I researched a little but the problem is I don't know the name of what I'm looking for =/
I have my personal framework that handles several common tasks in my projects and I also have some item templates to be used with that framework. I'd like to add code to specific classes (automatically) when I created a new class using my item template. I tried researching for code automation in VS add code item template and a lot of other weird word combinations...
I'll exemplify what I mean:
I have a class named Dandoran already created in a class library. Then I add a custom item template and on that moment I update class Dandoran with some specific code.
There's already a class in my class library named Dandoran
I create a new class, using my custom item template creation and name it Tatooine
At this moment, I (by I understand the item template or code automation, it's not really me going there and adding code) update class Dandoran with a code let's say this:
public static void HelloImCustomCodeAutomaticallyGenerated(){}
Does anyone know the name of this? And if you'd also have some sources, but only the name of the feature would already be great, since I could then start my research.
Thanks.
May be you are serching for Code Generation and T4 Text Templates?
http://msdn.microsoft.com/en-us/library/bb126445.aspx

How do I fix these C# errors?

I found some code to help me in a project and when I first ran the code I received an error message indicating: "Visual Studio cannot start debugging because the debug target c:\path\'dirInfo.exe' is missing. Please build the project and retry, or set the OutPath and AssemblyName properties appropriately to point at the correct location for the target assembly."
Then I select OK and receive an error message indicating that partial is missing. I add partial to the code and receive 3 more error messages.
The type 'RecursiveSearchCS.Form1' already contains a definition for 'components'
does this mean I should delete this from the Form1.cs file?
Type 'RecursiveSearchCS.Form1' already defines a member called 'Dispose' with the same parameter types.
Type 'RecursiveSearchCS.Form1' already defines a member called 'InitializeComponent' with the same parameter types.
(I notice, when I comment out the InitializeComponent line and/or Dispose line, many more error messages populate in ERRORS)
By they way you can find the original code # MicrosoftSite.
Any help would be greatly appreciated.
Thank You
Just gut instinct, if you were following along and copy pasting remember one key thing:
The designer creates two files when you create a form: A "code" file, and a "designer" file. However, when microsoft (and others) release "templates", they like to merge these two files.
Just create a new .cs file and paste the code and all should be good. It's the code basically saying "in the designer, we already have this stuff". (a good way to note this is the "partial" keyword located before your Form1 declaration)
More info:
The Code file will house all your own implementations. That is click events, methods you personally override, events you bind to, etc. This is the default file when you select "View Code" from either your solution explorer or the dialog itself. Within this file is a construct that calls a "hidden" method, (InitializeComponent) that if you right click and "Go to Definition" will bring you to the next file:
The Designer file is the IDE's generated file. This takes everything you do in the designer and stores it for you. That includes new controls, location and properties of the controls, and the IDisposable implementation. The idea is to keep the "meat an potatoes" out of the way while you worry only about implementation.
Yes it sounds like you've copied the entire code which includes many things already contained within your Form in a partial class. Either remove these or remove the partial class and partial class declaration from your Form to get rid of these errors
I went to the Microsoft site to see what you did. The site shows code for an entire "one file" solution. We've all agreed that Visual Studio creates multi-file solutions, so you're duplicating code.
I don't know if the current answers/comments have helped you get this sample code working, so I thought I'd add my share. I was able to get this sample working by doing the following:
First, where the sample code at the Microsoft site shows declarations for button, textbox, labels, and combobox, rather than attempting to copy that portion, I simply used the toolbox and dragged a button, the labels, the textbox, and the combobox from the toolbox to my form.
You'll probably want to arrange these to your liking.
This process created my form correctly with the appropriate objects on it. All I had to do was use the properties window for each object and rename them according to what they were named in the sample. For example, my new button was originally button1, but I renamed it to btnSearch just as it is named in the Microsoft sample.
I noticed that the Microsoft sample has an established event handler setup for the Form1_load() event. I created this same event in my form by clicking the form in the designer, clicking properties, clicking on the Events button in that properties, and double-clicking the "Load" event. This automatically generated the appropriate code.
In a similar way, I had to create the btnSearch_Click() event. I did this by simply double-clicking the button in the designer.
After that, all I had to do was manually copy and paste from the specific sections of the sample to my code -- fill in the Form1_Load() event with what was in the sample. Copy the DirSearch() method over. Fill in the btnSearch_Click() event. That was it.
I hope this helps solve the overall issue and gives you more insight into how you can avoid these problems in the future.
You have duplicated functionality in the classes, you have a file that was automatically generated with that functionality already in it.

Categories

Resources