How to generate empty get & set statements using CODEDOM in c#
c#-4.0
Solution
As Botz3000 mentioned, it's officially not possible. However, with the following hack you can implement it:
var field = new CodeMemberField
{
Attributes = MemberAttributes.Public | MemberAttributes.Final,
Name = "MyProperty",
Type = new CodeTypeReference(typeof(MyType)),
};
field.Name += " { get; set; }";
By appending `{ get; set; }` to the field name, it will generate a property in the actual source code.
Problem
currently the code which i have is generating the properties like ``` private int integerProperty { get { return integerField; } set { integerField = value; } } ``` I wanted the properties to be simple like... ``` private int integerProperty { get; set; } ``` The code i have with me is ``` CodeMemberProperty property1 = new CodeMemberProperty(); property1.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "integerField"))); property1.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "integerField"),new CodePropertySetValueReferenceExpression())); type1.Members.Add(property1); ``` Anyone please help. Thanks in advance.