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); }
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 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); }
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); }