public GroBufReader(long serializerId, IDataMembersExtractor dataMembersExtractor, IGroBufCustomSerializerCollection customSerializerCollection, GroBufOptions options, Func <Type, IGroBufCustomSerializer> factory, Func <Type, IGroBufCustomSerializer> baseFactory) { this.serializerId = serializerId; this.dataMembersExtractor = dataMembersExtractor; this.customSerializerCollection = customSerializerCollection; this.options = options; this.factory = factory; this.baseFactory = baseFactory; var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run); module = assembly.DefineDynamicModule(Guid.NewGuid().ToString()); readerCollection = new ReaderCollection(customSerializerCollection, factory, baseFactory, module); }
public Serializer(IDataMembersExtractor dataMembersExtractor, IGroBufCustomSerializerCollection customSerializerCollection = null, GroBufOptions options = GroBufOptions.None) { customSerializerCollection = customSerializerCollection ?? new DefaultGroBufCustomSerializerCollection(); Func <Type, IGroBufCustomSerializer> factory = type => new InternalSerializer(writer, reader, type, false); Func <Type, IGroBufCustomSerializer> baseFactory = type => new InternalSerializer(writer, reader, type, true); var id = Interlocked.Increment(ref serializerId) - 1; writer = new GroBufWriter(id, dataMembersExtractor, customSerializerCollection, options, factory, baseFactory); reader = new GroBufReader(id, dataMembersExtractor, customSerializerCollection, options, factory, baseFactory); if (options.HasFlag(GroBufOptions.WriteEmptyObjects)) { writerWritingEmptyObjects = writer; } else { id = Interlocked.Increment(ref serializerId) - 1; writerWritingEmptyObjects = new GroBufWriter(id, dataMembersExtractor, customSerializerCollection, options | GroBufOptions.WriteEmptyObjects, factory, baseFactory); } }
public GroBufWriter(long serializerId, IDataMembersExtractor dataMembersExtractor, IGroBufCustomSerializerCollection customSerializerCollection, GroBufOptions options, Func <Type, IGroBufCustomSerializer> factory, Func <Type, IGroBufCustomSerializer> baseFactory) { this.serializerId = serializerId; this.dataMembersExtractor = dataMembersExtractor; this.Options = options; sizeCounterCollection = new SizeCounterCollection(customSerializerCollection, factory, baseFactory); writerCollection = new WriterCollection(customSerializerCollection, factory, baseFactory); assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run); module = assembly.DefineDynamicModule(Guid.NewGuid().ToString()); trackReferences = options.HasFlag(GroBufOptions.PackReferences); }