/// <summary> /// Adds two fields to the class. /// </summary> public void AddFields(HtmlElementCollection htmls) { foreach (HtmlElement html in htmls) { string fieldName = html.Children[0].OuterText.Trim(); string fieldType = GetType(html.Children[1].OuterText.Trim()); string fieldMemo = html.Children[2].OuterText; // Declare the widthValue field. CodeMemberField widthValueField = new CodeMemberField(); widthValueField.Attributes = MemberAttributes.Private; widthValueField.CustomAttributes = new CodeAttributeDeclarationCollection { new CodeAttributeDeclaration("JsonProperty", new CodeAttributeArgument( new CodePrimitiveExpression(fieldName))) }; widthValueField.Name = "_" + CodeGenerationHelper.MakeFirstCharLowerCase(fieldName); widthValueField.Type = new CodeTypeReference(fieldType); widthValueField.Comments.Add(new CodeCommentStatement( fieldMemo)); targetClass.Members.Add(widthValueField); } }
/// <summary> /// Adds two fields to the class. /// </summary> public void AddFields(string fieldName, string fieldType, string fieldMemo) { // Declare the widthValue field. CodeMemberField widthValueField = new CodeMemberField(); widthValueField.Attributes = MemberAttributes.Private; widthValueField.CustomAttributes = new CodeAttributeDeclarationCollection { new CodeAttributeDeclaration("JsonProperty", new CodeAttributeArgument( new CodePrimitiveExpression(fieldName))) }; widthValueField.Name = "_" + CodeGenerationHelper.MakeFirstCharLowerCase(fieldName); widthValueField.Type = new CodeTypeReference(GetType(fieldType)); widthValueField.Comments.Add(new CodeCommentStatement( fieldMemo)); targetClass.Members.Add(widthValueField); }
/// <summary> /// Add three properties to the class. /// </summary> public void AddProperties(HtmlElementCollection htmls) { foreach (HtmlElement html in htmls) { string rePropertName = string.Empty; string propertName = html.Children[0].OuterText.Trim(); string propertType = GetType(html.Children[1].OuterText.Trim()); string propertMemo = html.Children[2].OuterText; // Declare the read-only Width property. CodeMemberProperty widthProperty = new CodeMemberProperty(); widthProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final; if (propertName.Substring(0, 1).ToUpper() == propertName.Substring(0, 1)) { rePropertName = CodeGenerationHelper.MakeFirstCharUpperCase(propertName); rePropertName = string.Format("ReName_{0}", rePropertName); widthProperty.Name = CodeGenerationHelper.MakeFirstCharUpperCase(rePropertName); } else { widthProperty.Name = CodeGenerationHelper.MakeFirstCharUpperCase(propertName); } widthProperty.HasGet = true; widthProperty.HasSet = true; widthProperty.Type = new CodeTypeReference(propertType); widthProperty.Comments.Add(new CodeCommentStatement( propertMemo)); widthProperty.GetStatements.Add(new CodeMethodReturnStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), "_" + CodeGenerationHelper.MakeFirstCharLowerCase(propertName)))); widthProperty.SetStatements.Add(new CodeAssignStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), "_" + CodeGenerationHelper.MakeFirstCharLowerCase(propertName)), new CodePropertySetValueReferenceExpression())); targetClass.Members.Add(widthProperty); } }