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?
C# CodeDom Automatic Property
Asked Answered
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).
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);
This is dangerous and not recommended, because all of the validation that comes with using CodeDom essentially goes out the window. –
Bettis
I guess I like to live dangerously. –
Otes
© 2022 - 2024 — McMap. All rights reserved.