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>
 /// </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)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="typeResolver"></param>
        /// <returns></returns>
        public static TypeModel Read(SQLiteConnection connection, TypeResolver typeResolver)
        {
            var model = new TypeModel();

            using (var command = connection.CreateCommand())
            {
                command.CommandText = string.Format("SELECT id, typename, baseId, surrogateId, underlyingEnumTypeId, classification FROM {0}", TypeTableName);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var id       = reader.GetInt32(i: 0);
                        var typeName = reader.GetString(i: 1);
                        int?baseId;
                        if (!reader.IsDBNull(i: 2))
                        {
                            baseId = reader.GetInt32(i: 2);
                        }
                        else
                        {
                            baseId = null;
                        }
                        int?surrogateId;
                        if (!reader.IsDBNull(3))
                        {
                            surrogateId = reader.GetInt32(3);
                        }
                        else
                        {
                            surrogateId = null;
                        }
                        int?underlyingEnumTypeId;
                        if (!reader.IsDBNull(4))
                        {
                            underlyingEnumTypeId = reader.GetInt32(4);
                        }
                        else
                        {
                            underlyingEnumTypeId = null;
                        }
                        var type = (TypeClassification)reader.GetInt32(5);
                        model.TryAddType(id, typeName, baseId, surrogateId, underlyingEnumTypeId, type, typeResolver);
                    }
                }
            }

            using (var command = connection.CreateCommand())
            {
                command.CommandText = string.Format("SELECT declaringTypeId, name, fieldId, fieldTypeId FROM {0}", FieldTableName);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var declaringTypeId = reader.GetInt32(0);
                        var fieldName       = reader.GetString(1);
                        var memberId        = reader.GetInt32(2);
                        var fieldTypeId     = reader.GetInt32(3);

                        var declaringType = model.TryGetTypeDescription(declaringTypeId);
                        if (declaringType != null)
                        {
                            var fieldType  = model.TryGetTypeDescription(fieldTypeId);
                            var memberInfo = FieldDescription.TryGetMemberInfo(declaringType.ResolvedType, fieldName);
                            if (memberInfo != null)
                            {
                                var memberDescription = FieldDescription.Create(memberInfo,
                                                                                fieldType,
                                                                                memberId);
                                declaringType.Add(memberDescription);
                            }
                            else
                            {
                                var memberDescription = new FieldDescription(fieldType,
                                                                             fieldName,
                                                                             null,
                                                                             memberId);
                                declaringType.Add(memberDescription);
                            }
                        }
                    }
                }
            }

            return(model);
        }