wizard
wizard

Reputation: 145

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

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?)

Upvotes: 0

Views: 105

Answers (2)

Rafalon
Rafalon

Reputation: 4515

Notepad++ can do it quite easily.

  • Open your text file with notepad++ and press Ctrl+H
  • Fill in the fields like below:
    • search for (.*)
    • replace with public string \1 {get;set;}
    • tick "regular expression"
    • press "Replace all"

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)

Upvotes: 2

Luke Parker
Luke Parker

Reputation: 354

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 C# Class from CSV tool.

Paste the contents and voila you have a C# model!

Upvotes: 3

Related Questions