private static CodeMemberField ToCodeMemberField(MessageField messageField, IDictionary <MessageDefinitions.Data.Enum, TypeInfo> typeInfoByEnum) { CodeMemberField codeMemberField = new CodeMemberField(); codeMemberField.Attributes = MemberAttributes.Private; codeMemberField.Name = GetFieldName(messageField.Name); // Type Type type = SystemTypeHelper.GetType(messageField.Type.DataType); CodeTypeReference codeTypeReference = GetCodeTypeReference(messageField.Type, type, typeInfoByEnum); codeMemberField.Type = codeTypeReference; if (messageField.Type.FieldType == FieldType.Array) { CodeArrayCreateExpression arrayCreateExpression = new CodeArrayCreateExpression(type, messageField.Type.ArrayLength); codeMemberField.InitExpression = arrayCreateExpression; } // Add summary comments CodeCommentStatement[] summaryCommentStatements = CodeCommentStatementHelper.GetSummaryCodeCommentStatements(messageField.Text); codeMemberField.Comments.AddRange(summaryCommentStatements); CodeCommentStatement[] remarksCommentStatements = CodeCommentStatementHelper.GetRemarksCodeCommentStatements(messageField.XmlDefinition.Name); codeMemberField.Comments.AddRange(remarksCommentStatements); return(codeMemberField); }
private static void AddEnumWriteCodeStatements(CodeStatementCollection statements, string writerParamName, MessageFieldType fieldType, CodePropertyReferenceExpression propertyExpression) { Type type = SystemTypeHelper.GetType(fieldType.DataType); CodeCastExpression castExpression = new CodeCastExpression(type, propertyExpression); CodeMethodInvokeExpression writeInvoke = new CodeMethodInvokeExpression( new CodeVariableReferenceExpression(writerParamName), "Write", castExpression); statements.Add(writeInvoke); }
private static CodeMemberProperty ToCodeMemberProperty(MessageField messageField, IDictionary <MessageDefinitions.Data.Enum, TypeInfo> typeInfoByEnum) { CodeMemberProperty codeMemberProperty = new CodeMemberProperty(); codeMemberProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final; codeMemberProperty.Name = messageField.Name; codeMemberProperty.HasGet = true; // Add metadata attribute String rawType = GetRawType(messageField); CodeAttributeDeclaration metadataAttributeDeclaration = CreateMessageFieldMetadataAttributeDeclaration(messageField.XmlDefinition.Name, rawType, messageField.Units, messageField.Display, messageField.Text); codeMemberProperty.CustomAttributes.Add(metadataAttributeDeclaration); // Type Type type = SystemTypeHelper.GetType(messageField.Type.DataType); CodeTypeReference codeTypeReference = GetCodeTypeReference(messageField.Type, type, typeInfoByEnum); codeMemberProperty.Type = codeTypeReference; string fieldName = GetFieldName(messageField.Name); // Getter codeMemberProperty.GetStatements.Add(new CodeMethodReturnStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), fieldName))); // Setter codeMemberProperty.SetStatements.Add(new CodeAssignStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), fieldName), new CodePropertySetValueReferenceExpression())); // Add summary comments CodeCommentStatement[] summaryCommentStatements = CodeCommentStatementHelper.GetSummaryCodeCommentStatements(messageField.Text); codeMemberProperty.Comments.AddRange(summaryCommentStatements); return(codeMemberProperty); }