C
C#4mo ago
hugi

child/parent class, how do i 'mass define' child properties?

So I have a class public class Parent: child { public IEnumerable<AdditionalProp> MoreStuff { get; set; } } public child { public int age { get; set; } public string name{ get; set; } public int score{ get; set; } .... (many more) } something like that... so if I have a value of Child a = data.getChild(); IEnumerable<AdditionalProp> b = data.getMoreStuff(); how do I make it so that I can put both into the Parent class without retrieving and setting the child variables (age, name etc.) separately? (without Automapper)
7 Replies
blueberriesiftheywerecats
$details
MODiX
MODiX4mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, what you expect the result to be, what .NET version you are using and what platform/environment (if any) are relevant to your question. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
blueberriesiftheywerecats
what do you mean by mass define?
hugi
hugiOP4mo ago
so instead of doing var x = data.getChild(); var y = new Parent() {age = x.age, name = x.name, score = x.score,......, MoreStuff = y} so i am looking for something cleaner like var y = new Parent() {child = x, MoreStuff = y} is there any way to do it so i don thave to define every single variable separately? since it is the child of the parent component it is obvious that i am going to name them all
ParaLogia
ParaLogia4mo ago
$code
MODiX
MODiX4mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
ParaLogia
ParaLogia4mo ago
You could just define a constructor that copies all those properties
Want results from more Discord servers?
Add your server