I use System.CodeDom to dynamically create a C++/CLI class and fill it with fields and methods.
When I fill methods with statements, everything is fine. However, when I insert class fields, I run into a problem of order.
For example, the following lines
CodeTypeDelegate delegateDecl = new CodeTypeDelegate("delegate_name");
CodeMemberField delegateField = new CodeMemberField(new CodeTypeReference(delegateDecl.Name), "delegate_field");
codeType.Members.Add(delegateDecl); /// the order of insertion - delegate declaration first !!!
codeType.Members.Add(delegateField); /// the order of insertion - field with the delegate usage second!!!
generates the following code: