Reputation: 3021
I am getting some Values into one of my Generic List like this
List<IGroup> Details = Operations.GetAllGroups();
Now I have a DTO which I need to use as List<DTO>
. Now I have to iterate through Details
and populate values into List using foreach loop.
How to do it? I tried but i am not able to get fields of the Details
List.
Update.. Tried like this..
foreach (var v in Details) {
group.Add(request.ActiveDirectoryGroupName = v.DisplayName, request.GroupDescription = v.Description, request.GroupTypeName = "", request.ApplicationIdentifier = "", request.ApplicationRightsDescription = "");
}
Here request is Calling the fields of the DTO.
Upvotes: 2
Views: 3150
Reputation: 117047
This should work for you:
List<DTO> dtos = Details.Select(v => new DTO()
{
ActiveDirectoryGroupName = v.DisplayName,
GroupDescription = v.Description,
GroupTypeName = "",
ApplicationIdentifier = "",
ApplicationRightsDescription = "",
}).ToList();
Upvotes: 3
Reputation: 1444
I think this is want you want:
List<DTO> DTO = new List<DTO>;
foreach (IGroup ele in Details)
{
DTO request = new DTO();
// here you can extract details properties.
request.ActiveDirectoryGroupName = ele.DisplayName;
...
...
DTO.Add(request);
}
Ofcourse you need to Edit as per your requirements.
Upvotes: 4