Exemplo n.º 1
0
        // --- protected ---
        protected void Save(object target, bool update)
        {
            var entity = EntityContainer.AsEntity(target);

            if (entity == null)
            {
                throw new ArgumentNullException("target");
            }

            var entityType = entity.Type;
            var id         = entity.Id;

            var settings = new XmlWriterSettings();
            {
                settings.Indent = false;
            }

            var swriter = new StringWriter();

            _NValues = 0;

            using (var writer = XmlWriter.Create(swriter, settings)) {
                var context = new StoreContext()
                {
                    Id     = id,
                    Type   = entityType,
                    Writer = writer,
                };

                writer.WriteStartDocument();
                {
                    SaveType(context, target, entityType);
                }
                writer.WriteEndDocument();
            }

            if (update)
            {
                _memoAccessor.UpdateEntity(entityType.FullName, id, swriter.ToString());
            }
            else
            {
                _memoAccessor.InsertEntity(entityType.FullName, id, swriter.ToString());
            }
        }