Home > database >  Is there any way to automatically add many properties on VS2019?
Is there any way to automatically add many properties on VS2019?

Time:10-27

Don't judge me, but I have an object with over 100 properties, most of them string. Is there anyway to automatically add them to the code, without extensive typing? I have them all in a text file with correct casing. I looked for plug ins, but couldn't find any (maybe using wrong keywords?)

CodePudding user response:

I am assuming your file looks like:

Property
SomeOtherProperty
Test

The easiest way would be to use a CSV -> C# Model generator

Steps

Change it to be comma separated, you can do this with C#:

var path = @"C:\Path\To\Your\File.txt";

var text = File.ReadAllText(path);
text = text.Replace(Environment.NewLine, ",");

File.WriteAllText(path, text);

Open the file and copy its contents to your clipboard.

Now open the before replace

And voilà:

after replace


Note that this should work with any editor that handle regex (as stated by @Klamsi in the comments section)

  • Related