Threadsafe TypeID -> TypeData list, which supports lockless reading.
Esempio n. 1
0
        /// <summary>
        /// Initialize NetSerializer
        /// </summary>
        /// <param name="typeMap">Type -> typeID map</param>
        /// <param name="settings">Settings</param>
        public Serializer(Dictionary <Type, uint> typeMap, Settings settings)
        {
            this.Settings = settings;

            if (this.Settings.CustomTypeSerializers.All(s => s is IDynamicTypeSerializer || s is IStaticTypeSerializer) == false)
            {
                throw new ArgumentException("TypeSerializers have to implement IDynamicTypeSerializer or IStaticTypeSerializer");
            }

            lock (m_modifyLock)
            {
                m_runtimeTypeMap    = new TypeDictionary();
                m_runtimeTypeIDList = new TypeIDList();

                AddTypesInternal(new Dictionary <Type, uint>()
                {
                    { typeof(object), Serializer.ObjectTypeId }
                });

                AddTypesInternal(typeMap);

                GenerateWriters(typeof(object));
                GenerateReaders(typeof(object));
            }
        }
Esempio n. 2
0
        Serializer(IEnumerable <Type> rootTypes, Settings settings, bool debugAssembly)
        {
            this.Settings = settings;

            if (this.Settings.CustomTypeSerializers.All(s => s is IDynamicTypeSerializer || s is IStaticTypeSerializer) == false)
            {
                throw new ArgumentException("TypeSerializers have to implement IDynamicTypeSerializer or  IStaticTypeSerializer");
            }

            var ab   = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("NetSerializerDebug"), AssemblyBuilderAccess.RunAndSave);
            var modb = ab.DefineDynamicModule("NetSerializerDebug.dll");
            var tb   = modb.DefineType("NetSerializer", TypeAttributes.Public);

            m_runtimeTypeMap    = new TypeDictionary();
            m_runtimeTypeIDList = new TypeIDList();

            lock (m_modifyLock)
            {
                var addedTypes = AddTypesInternal(new[] { typeof(object) }.Concat(rootTypes));

                /* generate stubs */
                foreach (var type in addedTypes.Keys)
                {
                    GenerateDebugStubs(type, tb);
                }

                foreach (var type in addedTypes.Keys)
                {
                    GenerateDebugBodies(type);
                }
            }

            tb.CreateType();
            ab.Save("NetSerializerDebug.dll");
        }
        /// <summary>
        /// Initialize NetSerializer
        /// </summary>
        /// <param name="typeMap">Type -> typeID map</param>
        /// <param name="settings">Settings</param>
        public Serializer(Dictionary <Type, uint> typeMap, Settings settings)
        {
            this.Settings = settings;

            lock (m_modifyLock)
            {
                m_runtimeTypeMap    = new TypeDictionary();
                m_runtimeTypeIDList = new TypeIDList();

                AddTypesInternal(new Dictionary <Type, uint>()
                {
                    { typeof(object), Serializer.ObjectTypeId }
                });

                AddTypesInternal(typeMap);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initialize NetSerializer
        /// </summary>
        /// <param name="rootTypes">Types to be (de)serialized</param>
        /// <param name="userTypeSerializers">Array of custom serializers</param>
        public Serializer(IEnumerable <Type> rootTypes, ITypeSerializer[] userTypeSerializers)
        {
            if (userTypeSerializers.All(s => s is IDynamicTypeSerializer || s is IStaticTypeSerializer) == false)
            {
                throw new ArgumentException("TypeSerializers have to implement IDynamicTypeSerializer or IStaticTypeSerializer");
            }

            m_userTypeSerializers = userTypeSerializers;

            lock (m_modifyLock)
            {
                m_runtimeTypeMap    = new TypeDictionary();
                m_runtimeTypeIDList = new TypeIDList();

                AddTypesInternal(new[] { typeof(object) }.Concat(rootTypes));

                GenerateWriters(typeof(object));
                GenerateReaders(typeof(object));
            }
        }