D
D
Dmitry Chudov2020-08-10 14:41:10
.NET
Dmitry Chudov, 2020-08-10 14:41:10

How to automatically initialize object properties?

Good afternoon.
There is an array of POCO objects with properties.
While there are 7 of these properties, there may be more.
From this array, another array of objects of the type I need is selectively created and values ​​are assigned to properties:

pocoList.ForEach(s => 
{
   new SomeTypeObject()
   {
      Id = s.Id,
      Path = s.Path
      Tag = s.Tag
   }
});

Everything works, but it's very interesting - is this a normal way to initialize properties or can it be done without manually writing all the properties? And if there are many properties, for example, dozens?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
#
#, 2020-08-10
@oZ-Zo

- this is the normal way
- the other way is the constructor
- do you know other ways?

R
Roman, 2020-08-10
@yarosroman

AutoMap is here to help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question