private static ServiceAssembly CreateAssemblyRegistration(Assembly assembly)
        {
            var messagesById = new ServiceMessageByIdCollection();
            var messagesByType = new ServiceMessageByTypeCollection();
            var typeModel = RuntimeTypeModel.Create();

            foreach (var type in assembly.GetTypes())
            {
                var messageAttributes = type.GetCustomAttributes(typeof(ProtoMessageAttribute), true);

                if (messageAttributes.Length == 0)
                    continue;

                Debug.Assert(messageAttributes.Length == 1);

                var contractAttributes = type.GetCustomAttributes(typeof(ProtoContractAttribute), true);

                if (contractAttributes.Length == 0)
                    throw new ProtoChannelException(String.Format("Type '{0}' specifies the ProtoMessage attribute but not the ProtoContract attribute", type));

                var messageAttribute = (ProtoMessageAttribute)messageAttributes[0];

                var message = new ServiceMessage(messageAttribute, type);

                messagesById.Add(message);
                messagesByType.Add(message);

                typeModel.Add(type, true);
            }

            if (messagesById.Count == 0)
                throw new ProtoChannelException(String.Format("Assembly '{0}' does not contain any messages", assembly));

            return new ServiceAssembly(assembly, typeModel, messagesById, messagesByType);
        }
        public ServiceAssembly(Assembly assembly, RuntimeTypeModel typeModel, ServiceMessageByIdCollection messagesById, ServiceMessageByTypeCollection messagesByType)
        {
            Require.NotNull(assembly, "assembly");
            Require.NotNull(typeModel, "typeModel");
            Require.NotNull(messagesById, "messagesById");
            Require.NotNull(messagesByType, "messagesByType");

            Assembly = assembly;
            TypeModel = typeModel;
            MessagesById = messagesById;
            MessagesByType = messagesByType;
        }