I need to initialize my object like below:
var obj = new EduBranch {
Id = model.Id,
WorklevelId = model.WorklevelId,
EdulevelId = model.EdulevelId,
Title = model.Title,
StartEduYearId = model.StartEduYearId,
EndEduYearId = model.EndEduYearId,
};
but in CodeDOM I could only find:
var objectCreate1 = new CodeObjectCreateExpression("EduBranch",
new CodeExpression[]{});
and this is using parentheses to initialize instead of brackets. is there a CodeDOM approach for this? ( I already make my code using stringBuilder but I'm looking for a CodeDOM approach ) thanks
The CodeDom doesn't currently support object initializers (or collection initializers, for that matter).
The CodeDom has fallen out of favor over the years, because of other technologies (T4 templates, for example).
That said, because this line:
var obj = new EduBranch {
Id = model.Id,
WorklevelId = model.WorklevelId,
EdulevelId = model.EdulevelId,
Title = model.Title,
StartEduYearId = model.StartEduYearId,
EndEduYearId = model.EndEduYearId,
};
Is effectively the same as:
var obj = new EduBranch();
obj.Id = model.Id;
obj.WorklevelId = model.WorklevelId;
obj.EdulevelId = model.EdulevelId;
obj.Title = model.Title;
obj.StartEduYearId = model.StartEduYearId;
obj.EndEduYearId = model.EndEduYearId;
You can use the CodeDOM to generate the above, and get the same
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With