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); }
private static CodeTypeDeclaration ToCodeTypeDeclaration(MessageDefinitions.Data.Message message, string className, TypeInfo serializerInterfaceTypeInfo, TypeInfo messageBaseClassTypeInfo, String messagesNamespace) { CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration() { Name = className, IsClass = true }; codeTypeDeclaration.BaseTypes.Add(serializerInterfaceTypeInfo.FullName); CodeMemberMethod serializeCodeMemberMethod = CreateSerializeCodeMemberMethod(messageBaseClassTypeInfo, message, messagesNamespace); codeTypeDeclaration.Members.Add(serializeCodeMemberMethod); CodeMemberMethod deserializeCodeMemberMethod = CreateDeserializeCodeMemberMethod(messageBaseClassTypeInfo, message); codeTypeDeclaration.Members.Add(deserializeCodeMemberMethod); return(codeTypeDeclaration); }
private static void GenerateMessageClassFile(MessageGenerationParams pParams, MessageDefinitions.Data.Message message, CodeGeneratorOptions options, CodeDomProvider codeProvider, IDictionary <MessageDefinitions.Data.Enum, TypeInfo> enumTypeInfoByName) { TypeInfo typeInfo = TypeInfoHelper.GetTypeInfo(pParams.Namespace, message); string filename = TypeInfoHelper.GetFilename(typeInfo); String filePath = Path.Combine(pParams.OutputPath, filename); CodeCompileUnit unit = MessageGeneratorHelper.CreateCodeCompileUnit(typeInfo, message, pParams.BaseClassTypeInfo, pParams.MessageTypeEnumTypeInfo, enumTypeInfoByName); codeProvider.GenerateCodeFromCompileUnit(unit, options, filePath); }
private static CodeAttributeDeclaration CreateDescriptionAttributeDeclaration(MessageDefinitions.Data.Message message) { CodeAttributeDeclaration codeAttributeDeclaration = new CodeAttributeDeclaration("Description", new CodeAttributeArgument(new CodePrimitiveExpression(message.Description))); return(codeAttributeDeclaration); }