///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  true this instance to the given stream.
        /// </summary>
        /// <param name="stream">
        ///  The stream.
        /// </param>
        /// <param name="domain">
        ///  The domain.
        /// </param>
        /// <param name="settings">
        ///  (Optional) options for controlling the operation.
        /// </param>
        /// <param name="elements">
        ///  (Optional) the elements.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        public static void Serialize(Stream stream, IDomainModel domain, SerializationSettings settings = null, IEnumerable <IModelElement> elements = null)
        {
            Contract.Requires(stream, "stream");
            Contract.Requires(domain, "domain");

            if (settings == null)
            {
                settings = new SerializationSettings();
            }
            var ser = new HyperstoreSerializer(domain, settings);

            ser.Serialize(stream,
                          elements != null ? elements.OfType <IModelEntity>() : domain.GetEntities(),
                          elements != null ? elements.OfType <IModelRelationship>() : domain.GetRelationships());
        }
        public static string SerializeScope(IDomainScope scope)
        {
            string result = null;

            using (var writer = new MemoryStream())
            {
                var settings = new SerializationSettings();
                var ser      = new HyperstoreSerializer(scope, settings);
                ser.Serialize(writer,
                              scope.GetScopeElements().OfType <IModelEntity>(),
                              scope.GetScopeElements().OfType <IModelRelationship>(),
                              new HashSet <Identity>(scope.GetDeletedElements().Where(node => node.NodeType == NodeType.Node).Select(node => node.Id)),
                              new HashSet <Identity>(scope.GetDeletedElements().Where(node => node.NodeType == NodeType.Edge).Select(node => node.Id))
                              );
                writer.Position = 0;
                using (var reader = new StreamReader(writer))
                {
                    result = reader.ReadToEnd();
                }
            }
            return(result);
        }