Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbClassData"/> class.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="columns">The columns.</param>
        /// <param name="formatter">The formatter.</param>
        /// <param name="dataReaderReadMethods">The data reader read methods.</param>
        /// <param name="columnCollections">The column collections.</param>
        /// <param name="customTypes">The custom types.</param>
        public DbClassData(string tableName, IEnumerable<DbColumnInfo> columns, CodeFormatter formatter,
                           Dictionary<Type, string> dataReaderReadMethods, IEnumerable<ColumnCollection> columnCollections,
                           IEnumerable<CustomTypeMapping> customTypes)
        {
            const string tableNameWildcard = "*";

            _tableName = tableName;
            _columns = columns.OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase);
            _formatter = formatter;
            _dataReaderReadMethods = dataReaderReadMethods;

            _className = formatter.GetClassName(tableName);
            _interfaceName = formatter.GetInterfaceName(tableName);
            _extensionClassName = ClassName + "DbExtensions";

            // Custom types filter
            _customTypes =
                customTypes.Where(
                    x =>
                    x.Columns.Count() > 0 &&
                    (x.Tables.Contains(TableName, StringComparer.OrdinalIgnoreCase) || x.Tables.Contains(tableNameWildcard))).
                    ToCompact();

            // Column collections filter
            _columnCollections =
                columnCollections.Where(
                    x =>
                    x.Columns.Count() > 0 &&
                    (x.Tables.Contains(TableName, StringComparer.OrdinalIgnoreCase) || x.Tables.Contains(tableNameWildcard))).
                    OrderBy(x => x.CollectionPropertyName).ToCompact();

            // Populate the external types dictionary
            foreach (var column in columns)
            {
                var columnName = column.Name;
                string externalType;
                var customType = _customTypes.FirstOrDefault(x => x.Columns.Contains(columnName, StringComparer.OrdinalIgnoreCase));
                if (customType != null)
                    externalType = customType.CustomType;
                else
                    externalType = GetInternalType(column);

                _externalTypes.Add(column, externalType);
            }

            // Populate the naming dictionaries
            foreach (var column in columns)
            {
                _privateNames.Add(column,
                    formatter.GetFieldName(column.Name, MemberVisibilityLevel.Private, GetInternalType(column)));
                _publicNames.Add(column,
                    formatter.GetFieldName(column.Name, MemberVisibilityLevel.Public, GetExternalType(column)));
                _parameterNames.Add(column, formatter.GetParameterName(column.Name, column.Type));
            }
        }
Ejemplo n.º 2
0
        static IEnumerable<ColumnCollectionItem> GetStatColumnCollectionItems(CodeFormatter formatter, StatCollectionType statCollectionType)
        {
            var columnItems = new List<ColumnCollectionItem>();
            foreach (var statType in EnumHelper<StatType>.Values)
            {
                var dbField = statType.GetDatabaseField(statCollectionType);
                var item = ColumnCollectionItem.FromEnum(formatter, dbField, statType);
                columnItems.Add(item);
            }

            return columnItems;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="ColumnCollectionItem"/> from an enum.
        /// </summary>
        /// <typeparam name="T">The key type.</typeparam>
        /// <param name="formatter">The <see cref="CodeFormatter"/>.</param>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="key">The key to use.</param>
        /// <returns>The resulting <see cref="ColumnCollectionItem"/>.</returns>
        public static ColumnCollectionItem FromEnum <T>(CodeFormatter formatter, string columnName, T key)
        {
            var keyStr = formatter.GetTypeString(typeof(T)) + "." + key;

            return(new ColumnCollectionItem(columnName, keyStr));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomTypeMapping"/> class.
 /// </summary>
 /// <param name="tables">The tables.</param>
 /// <param name="columns">The columns.</param>
 /// <param name="customType">Type of the custom.</param>
 /// <param name="formatter">The formatter.</param>
 public CustomTypeMapping(IEnumerable<string> tables, IEnumerable<string> columns, Type customType, CodeFormatter formatter)
     : this(tables, columns, formatter.GetTypeString(customType))
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MethodParameter"/> struct.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="type">The type.</param>
 /// <param name="formatter">The formatter.</param>
 public MethodParameter(string name, Type type, CodeFormatter formatter)
 {
     _name = name;
     _type = formatter.GetTypeString(type);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomTypeMapping"/> class.
 /// </summary>
 /// <param name="tables">The tables.</param>
 /// <param name="columns">The columns.</param>
 /// <param name="customType">Type of the custom.</param>
 /// <param name="formatter">The formatter.</param>
 public CustomTypeMapping(IEnumerable <string> tables, IEnumerable <string> columns, Type customType, CodeFormatter formatter)
     : this(tables, columns, formatter.GetTypeString(customType))
 {
 }