I have a property created with CodeDom. How can I set it to being an automatic property instead of adding CodeFieldReferenceExpressions against a private member?
Asked
Active
Viewed 4,416 times
2 Answers
12
IIRC, CodeDom simply doesn't have a way of expressing this. Automatically implemented properties are just compiler sugar, but since it doesn't map (cleanly) to all languages, it doesn't fit cleanly into CodeDom (besides, CodeDom would have needed an update).

Marc Gravell
- 1,026,079
- 266
- 2,566
- 2,900
9
Yes you can.
You can use CodeSnippetTypeMember class for that purpose.
For example:
CodeTypeDeclaration newType = new CodeTypeDeclaration("TestType");
CodeSnippetTypeMember snippet = new CodeSnippetTypeMember();
snippet.Comments.Add(new CodeCommentStatement("this is integer property", true));
snippet.Text="public int IntergerProperty { get; set; }";
newType.Members.Add(snippet);

bigkahunaburger
- 426
- 5
- 10
-
This is dangerous and not recommended, because all of the validation that comes with using CodeDom essentially goes out the window. – Ian Kemp Aug 23 '21 at 11:40
-
I guess I like to live dangerously. – bigkahunaburger Sep 02 '21 at 16:33