Ejemplo n.º 1
0
        private static GenericSerializer <T> CreateSerializerFor <T>(params Type[] additionalTypes)
        {
            var types = new List <Type>(additionalTypes)
            {
                typeof(T)
            };
            var typeModel         = TypeModel.Create(types);
            var protoBufTypeModel = ProtobufTypeModel.Compile(typeModel);
            var serializer        = new Serializer(new CompiledTypeModel(protoBufTypeModel, typeModel));

            return(new GenericSerializer <T>(serializer));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Creates a new type model from the types stored in the given database *and* the
        ///     given specified types. Types in the database which are not part of the given list
        ///     are simply ignored. Types in the given list which are not part of the database are
        ///     added to it.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="supportedTypes"></param>
        /// <param name="isReadOnly"></param>
        /// <returns></returns>
        public static CompiledTypeModel Create(SQLiteConnection connection,
                                               IEnumerable <Type> supportedTypes,
                                               bool isReadOnly = false)
        {
            var allTypes         = BuiltInTypes.Concat(supportedTypes).ToList();
            var currentTypeModel = TypeModel.Create(allTypes);
            var typeResolver     = new TypeResolver(currentTypeModel.TypeDescriptions);
            var typeModel        = TypeModel.Read(connection, typeResolver);

            typeModel.Add(currentTypeModel);

            // If we reach this point, then both type models are compatible to each other
            // and we can create a serializer for it!
            var serializer = Compile(typeModel);

            if (!isReadOnly)
            {
                // Now that the serializer is compiled, we should also update the typemodel in the database.
                typeModel.Write(connection);
            }

            return(new CompiledTypeModel(serializer, typeModel));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// </summary>
 /// <param name="supportedTypes">The list of types for which a mapping shall be provided</param>
 public TypeResolver(IEnumerable <Type> supportedTypes)
     : this(TypeModel.Create(supportedTypes).TypeDescriptions)
 {
 }