Visual Studio uploads all class properties to the editor

Well, here is one for people who have a lot of handy little extras for the visual studio or can help with the keystroke sequence.

Say I have a Person class:

class Person
{
    string Name { get; set; }
    int Age { get; set; }
}

And I'm busy coding away happily. I often get a situation where I need to assign values ​​to all the properties of this class or assign all the values ​​of the properties to something else.

public override void CopyTo(Person myPerson)
{
    myPerson.Name = "XXX";
    myPerson.Age = 11;
}

I would like to generate this part:

myPerson.Name
myPerson.Age

those. Just reset all myPerson properties under each other in a small list. In the editor of Visual Studio.

I have resharper installed, and I quickly looked through a utility that does this on purpose, but I could not find it. Who can help?

+4
4

(3. Visual Studio) Visual Commander, .

+2

#, Visual Studio 2015

> #r "C:/MyApp/bin/Debug/Foo.dll"
> using MyApp;
> var personType = typeof(Person);
> var personProperties = personType.GetProperties();
> foreach(var personProperty in personProperty) { Console.WriteLine($"{nameof(Person)}.{personProperty.Name}"); }

, , , .

, , , " ".

+6

All you have to do is print the object in the Immediate Visual Studio window, you do not need R #.

eg.? Myperson

And all your properties will print as you want.

List of Values ​​of a Class

0
source

C # Immediate window is great! This is a single line font for printing properties in some format. Just play with it according to your needs:

typeof(MyApp.Person).GetProperties().Select(x => x.Name).Aggregate((x, y)=>x +", " +y)
0
source

All Articles