private static CodeMemberField ToCodeMemberField(EnumEntry enumEntry)
        {
            CodeMemberField field = new CodeMemberField();

            field.Name = enumEntry.Name;

            if (enumEntry.Value.HasValue)
            {
                field.InitExpression = new CodePrimitiveExpression(enumEntry.Value);
            }

            string[] lines = GetSummaryCommentLines(enumEntry);

            // Add summary comments
            CodeCommentStatement[] summaryCommentStatements = CodeCommentStatementHelper.GetSummaryCodeCommentStatements(lines);
            field.Comments.AddRange(summaryCommentStatements);

            if (enumEntry.IsNameTransformed)
            {
                // Add remarks comments
                CodeCommentStatement[] remarksCommentStatements = CodeCommentStatementHelper.GetRemarksCodeCommentStatements(enumEntry.XmlDefinition.Name);
                field.Comments.AddRange(remarksCommentStatements);
            }

            // Add description attribute
            CodeAttributeDeclaration descriptionAttributeDeclaration = CreateDescriptionAttributeDeclaration(enumEntry);

            field.CustomAttributes.Add(descriptionAttributeDeclaration);
            return(field);
        }
        private static CodeTypeDeclaration ToCodeTypeDeclaration(MessageDefinitions.Data.Enum enumeration)
        {
            CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration()
            {
                Name   = enumeration.Name,
                IsEnum = true
            };

            // Add summary comments
            CodeCommentStatement[] summaryCommentStatements = CodeCommentStatementHelper.GetSummaryCodeCommentStatements(enumeration.Description);
            codeTypeDeclaration.Comments.AddRange(summaryCommentStatements);

            if (enumeration.IsNameTransformed)
            {
                // Add remarks comments
                CodeCommentStatement[] remarksCommentStatements = CodeCommentStatementHelper.GetRemarksCodeCommentStatements(enumeration.XmlDefinition.Name);
                codeTypeDeclaration.Comments.AddRange(remarksCommentStatements);
            }

            // Add values
            foreach (EnumEntry enumEntry in enumeration.Entries)
            {
                CodeMemberField field = ToCodeMemberField(enumEntry);
                codeTypeDeclaration.Members.Add(field);
            }

            return(codeTypeDeclaration);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        private static CodeMemberField ToCodeMemberField(MessageDefinitions.Data.Message message)
        {
            CodeMemberField field = new CodeMemberField
            {
                Name           = message.Name,
                InitExpression = new CodePrimitiveExpression(message.Id)
            };

            // Add summary comments
            CodeCommentStatement[] summaryCommentStatements = CodeCommentStatementHelper.GetSummaryCodeCommentStatements(message.Description);
            field.Comments.AddRange(summaryCommentStatements);

            if (message.IsNameTransformed)
            {
                // Add remarks comments
                CodeCommentStatement[] remarksCommentStatements = CodeCommentStatementHelper.GetRemarksCodeCommentStatements(message.XmlDefinition.Name);
                field.Comments.AddRange(remarksCommentStatements);
            }

            // Add description attribute
            CodeAttributeDeclaration descriptionAttributeDeclaration = CreateDescriptionAttributeDeclaration(message);

            field.CustomAttributes.Add(descriptionAttributeDeclaration);
            return(field);
        }
Exemple #5
0
        private static CodeTypeDeclaration ToCodeTypeDeclaration(TypeInfo typeInfo, MessageDefinitions.Data.Message message, TypeInfo messageBaseClassTypeInfo, string messageTypeEnumValue, IDictionary <MessageDefinitions.Data.Enum, TypeInfo> typeInfoByEnum)
        {
            CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration()
            {
                Name    = typeInfo.Name,
                IsClass = true
            };

            // Add metadata attribute
            CodeAttributeDeclaration metadataAttributeDeclaration = CreateMessageMetadataAttributeDeclaration(messageTypeEnumValue, message.XmlDefinition.Name, message.Description);

            codeTypeDeclaration.CustomAttributes.Add(metadataAttributeDeclaration);

            codeTypeDeclaration.BaseTypes.Add(messageBaseClassTypeInfo.FullName);
            AddConstructor(codeTypeDeclaration, messageTypeEnumValue);

            // Add summary comments
            CodeCommentStatement[] summaryCommentStatements = CodeCommentStatementHelper.GetSummaryCodeCommentStatements(message.Description);
            codeTypeDeclaration.Comments.AddRange(summaryCommentStatements);

            if (message.IsNameTransformed)
            {
                CodeCommentStatement[] remarksCommentStatements = CodeCommentStatementHelper.GetRemarksCodeCommentStatements(message.XmlDefinition.Name);
                codeTypeDeclaration.Comments.AddRange(remarksCommentStatements);
            }

            // Add fields
            foreach (MessageField messageField in message.Fields)
            {
                CodeMemberField codeMemberField = ToCodeMemberField(messageField, typeInfoByEnum);
                codeTypeDeclaration.Members.Add(codeMemberField);
            }

            // Add properties
            foreach (MessageField messageField in message.Fields)
            {
                CodeMemberProperty codeMemberProperty = ToCodeMemberProperty(messageField, typeInfoByEnum);
                codeTypeDeclaration.Members.Add(codeMemberProperty);
            }

            return(codeTypeDeclaration);
        }
Exemple #6
0
        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);
        }