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:
Is effectively the same as:
You can use the CodeDOM to generate the above, and get the same