Esempio n. 1
0
        /// <summary>
        /// Add a <see cref="ForeignKeyDefinition"/> to the table
        /// </summary>
        /// <paramm name="foreignKey">The <see cref="ForeignKeyDefinition"/> to add to <see cref="ForeignKeys"/></paramm>
        /// <exception cref="ArgumentNullException"></exception>
        public void AddForeignKey(ForeignKeyDefinition foreignKey)
        {
            if (foreignKey == null)
            {
                throw new ArgumentNullException(nameof(foreignKey));
            }

            ForeignKeys.Add(foreignKey);
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves all foreigns keys for the table
        /// </summary>
        /// <param name="assemblyFilePath">The assembly file to search</param>
        /// <remarks><see cref="CompleteForeignKeyDefinitions"/> should be called after this function.</remarks>
        public void GetForeignKeys(string assemblyFilePath)
        {
            Type type = AssemblySearch.GetTypeFromAssembly(assemblyFilePath, FullClassNamespace);

            //Search fields
            foreach (var field in TypeSearch.GetFieldsWithScriptForeignKeyAttribute(type) ?? new FieldInfo[0])
            {
                AddForeignKey(ForeignKeyDefinition.CreateFromFieldInfo(field, Name));
            }

            //Search properties
            foreach (var property in TypeSearch.GetPropertiesWithScriptForeignKeyAttribute(type) ?? new PropertyInfo[0])
            {
                AddForeignKey(ForeignKeyDefinition.CreateFromPropertyInfo(property, Name));
            }

#if DEBUG
            foreach (ForeignKeyDefinition fk in ForeignKeys)
            {
                Console.WriteLine($"Table: {Name} - Foreign Key: {fk.ColumnName}, {fk.ForeignTable}");
            }
#endif
        }