/// <exception cref="System.IO.IOException" />
        public IClassDefinition LookupOrRegisterClassDefinition(IPortable p)
        {
            var portableVersion = PortableVersionHelper.GetVersion(p, _version);
            var cd = LookupClassDefinition(p.FactoryId, p.ClassId, portableVersion);

            if (cd == null)
            {
                var writer = new ClassDefinitionWriter(this, p.FactoryId, p.ClassId, portableVersion);
                p.WritePortable(writer);
                cd = writer.RegisterAndGet();
            }
            return(cd);
        }
        /// <exception cref="System.IO.IOException"></exception>
        public void WritePortable(string fieldName, IPortable portable)
        {
            if (portable == null)
            {
                throw new SerializationException("Cannot write null portable without explicitly "
                                                 + "registering class definition!");
            }
            var version        = PortableVersionHelper.GetVersion(portable, _context.GetVersion());
            var nestedClassDef = CreateNestedClassDef(portable, new ClassDefinitionBuilder
                                                          (portable.FactoryId, portable.ClassId, version));

            _builder.AddPortableField(fieldName, nestedClassDef);
        }
Пример #3
0
        private int FindPortableVersion(int factoryId, int classId, IPortable portable)
        {
            var currentVersion = _context.GetClassVersion(factoryId, classId);

            if (currentVersion < 0)
            {
                currentVersion = PortableVersionHelper.GetVersion(portable, _context.GetVersion());
                if (currentVersion > 0)
                {
                    _context.SetClassVersion(factoryId, classId, currentVersion);
                }
            }
            return(currentVersion);
        }
        /// <exception cref="System.IO.IOException"></exception>
        public void WritePortableArray <TPortable>(string fieldName, TPortable[] portables) where TPortable : IPortable
        {
            if (portables == null || portables.Length == 0)
            {
                throw new SerializationException("Cannot write null portable array without explicitly "
                                                 + "registering class definition!");
            }
            var p       = portables[0];
            var classId = p.ClassId;

            for (var i = 1; i < portables.Length; i++)
            {
                if (portables[i].ClassId != classId)
                {
                    throw new ArgumentException("Detected different class-ids in portable array!");
                }
            }
            var version        = PortableVersionHelper.GetVersion(p, _context.GetVersion());
            var nestedClassDef = CreateNestedClassDef(p, new ClassDefinitionBuilder
                                                          (p.FactoryId, classId, version));

            _builder.AddPortableArrayField(fieldName, nestedClassDef);
        }