public static Message Convert(Group group, Message groupMsg, ConversionContext context)
        {
            SetNameAndId(group, groupMsg);
            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)SessionControlProtocol11
                        .TypeRef
                        .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            var instructions = new SequenceValue(
                SessionControlProtocol11.TemplateDefinition.GetSequence("Instructions"));

            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)
                        SessionControlProtocol11
                        .TypeRef
                        .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            Field[] fields = group.FieldDefinitions;
            for (int i = group is MessageTemplate ? 1 : 0; i < fields.Length; i++)
            {
                Field field = fields[i];

                IFieldInstructionConverter converter = context.GetConverter(field);
                if (converter == null)
                {
                    throw new InvalidOperationException("No converter found for type " + field.GetType());
                }

                IFieldValue v = converter.Convert(field, context);
                instructions.Add(new[] { v });
            }
            groupMsg.SetFieldValue("Instructions", instructions);
            return(groupMsg);
        }
        public static Message Convert(Group group, Message groupMsg, ConversionContext context)
        {
            SetNameAndId(group, groupMsg);
            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group) SessionControlProtocol11
                                    .TypeRef
                                    .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            var instructions = new SequenceValue(
                SessionControlProtocol11.TemplateDefinition.GetSequence("Instructions"));

            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)
                        SessionControlProtocol11
                            .TypeRef
                            .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            Field[] fields = group.FieldDefinitions;
            for (int i = group is MessageTemplate ? 1 : 0; i < fields.Length; i++)
            {
                Field field = fields[i];

                IFieldInstructionConverter converter = context.GetConverter(field);
                if (converter == null)
                    throw new InvalidOperationException("No converter found for type " + field.GetType());

                IFieldValue v = converter.Convert(field, context);
                instructions.Add(new[] {v});
            }
            groupMsg.SetFieldValue("Instructions", instructions);
            return groupMsg;
        }
        public static Field[] ParseFieldInstructions(GroupValue groupDef, ITemplateRegistry registry,
                                                     ConversionContext context)
        {
            SequenceValue instructions = groupDef.GetSequence("Instructions");
            var           fields       = new Field[instructions.Length];

            for (int i = 0; i < fields.Length; i++)
            {
                GroupValue fieldDef = instructions[i].GetGroup(0);
                IFieldInstructionConverter converter = context.GetConverter(fieldDef.Group);
                if (converter == null)
                {
                    throw new SystemException(
                              string.Format("Encountered unknown group {0} while processing field instructions {1}",
                                            fieldDef.Group, groupDef.Group));
                }

                fields[i] = converter.Convert(fieldDef, registry, context);
            }
            return(fields);
        }
        public static Field[] ParseFieldInstructions(GroupValue groupDef, ITemplateRegistry registry,
                                                     ConversionContext context)
        {
            SequenceValue instructions = groupDef.GetSequence("Instructions");
            var fields = new Field[instructions.Length];
            for (int i = 0; i < fields.Length; i++)
            {
                GroupValue fieldDef = instructions[i].GetGroup(0);
                IFieldInstructionConverter converter = context.GetConverter(fieldDef.Group);
                if (converter == null)
                    throw new SystemException(
                        string.Format("Encountered unknown group {0} while processing field instructions {1}",
                                      fieldDef.Group, groupDef.Group));

                fields[i] = converter.Convert(fieldDef, registry, context);
            }
            return fields;
        }