protected void CreatePropertyForObject (Type type, string propName, string fieldName, bool isPublic)
{
CodeFieldReferenceExpression field = new CodeFieldReferenceExpression (thisRef, fieldName);
CodeMemberProperty prop = new CodeMemberProperty ();
prop.Type = new CodeTypeReference (type);
prop.Name = propName;
if (isPublic)
prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;
else
prop.Attributes = MemberAttributes.Private | MemberAttributes.Final;
CodeConditionStatement stmt = new CodeConditionStatement();
stmt.Condition = new CodeBinaryOperatorExpression (field,
CodeBinaryOperatorType.IdentityEquality,
new CodePrimitiveExpression (null));
CodeObjectCreateExpression create = new CodeObjectCreateExpression (prop.Type);
stmt.TrueStatements.Add (new CodeAssignStatement (field, create));
prop.GetStatements.Add (stmt);
prop.GetStatements.Add (new CodeMethodReturnStatement (field));
mainClass.Members.Add (prop);
}
/******/