Пример #1
0
        // Initializers
        private static void InitializeTable(Type tableType)
        {
            lock (PropertyInfoToColumnDesc) {
                if (TablesInitialized.Contains(tableType))
                {
                    return;
                }

                var tableAttribute = tableType.GetCustomAttribute <KDPgTableAttribute>();

                if (tableAttribute == null)
                {
                    return;
                }

                var table = new KdPgTableDescriptor(
                    modelType: tableType,
                    name: tableAttribute.Name,
                    schema: tableAttribute.Schema);

                table.Columns = tableType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                .Where(x => x.GetCustomAttribute <KDPgColumnAttribute>() != null)
                                .Select(x => CreateColumnDescriptor(x, table)).ToList();

                foreach (var col in table.Columns)
                {
                    PropertyInfoToColumnDesc[col.PropertyInfo] = col;
                }

                TypeToTableDesc[tableType] = table;

                TablesInitialized.Add(tableType);
            }
        }
        public void AddModelEntry(KdPgTableDescriptor table)
        {
            fieldsCount += 1 + table.Columns.Count;

            Entries.Add(new Entry {
                MemberPgTable = table,
            });
        }
Пример #3
0
        private static KdPgColumnDescriptor CreateColumnDescriptor(PropertyInfo columnPropertyInfo, KdPgTableDescriptor table)
        {
            var columnAttribute = columnPropertyInfo.GetCustomAttribute <KDPgColumnAttribute>();

            if (columnAttribute == null)
            {
                throw new Exception("no column info");
            }

            return(new KdPgColumnDescriptor(
                       name: columnAttribute.Name,
                       flags: columnAttribute.Flags,
                       type: PgTypesConverter.CreatePgValueTypeFromProperty(columnPropertyInfo),
                       propertyInfo: columnPropertyInfo,
                       table: table));
        }