diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-04-18 13:53:54 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-04-18 21:25:30 +1000 |
| commit | 1c933963d1354495d4a31a08baf7f1240b5fbfce (patch) | |
| tree | f2190fc0336f57d3c6b408e1a5d57b0b9c343092 /src/WixToolset.Data/WindowsInstaller/TableDefinition.cs | |
| parent | 2b3c14c790e8a95edabecf2d7bb50baa58d8e95b (diff) | |
| download | wix-1c933963d1354495d4a31a08baf7f1240b5fbfce.tar.gz wix-1c933963d1354495d4a31a08baf7f1240b5fbfce.tar.bz2 wix-1c933963d1354495d4a31a08baf7f1240b5fbfce.zip | |
Add ability for an extension to have a custom strongly typed row during binding.
Remove some unused functionality in Table and Row.
Use strongRowType in core tables.
Diffstat (limited to 'src/WixToolset.Data/WindowsInstaller/TableDefinition.cs')
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/TableDefinition.cs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs index 7c4a3e9d..9ec37895 100644 --- a/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs +++ b/src/WixToolset.Data/WindowsInstaller/TableDefinition.cs | |||
| @@ -26,18 +26,22 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 26 | /// <param name="columns">Column definitions for the table.</param> | 26 | /// <param name="columns">Column definitions for the table.</param> |
| 27 | /// <param name="unreal">Flag if table is unreal.</param> | 27 | /// <param name="unreal">Flag if table is unreal.</param> |
| 28 | /// <param name="tupleIdIsPrimaryKey">Whether the primary key is the id of the tuple definition associated with this table.</param> | 28 | /// <param name="tupleIdIsPrimaryKey">Whether the primary key is the id of the tuple definition associated with this table.</param> |
| 29 | public TableDefinition(string name, IntermediateTupleDefinition tupleDefinition, IEnumerable<ColumnDefinition> columns, bool unreal = false, bool tupleIdIsPrimaryKey = false) | 29 | public TableDefinition(string name, IntermediateTupleDefinition tupleDefinition, IEnumerable<ColumnDefinition> columns, bool unreal = false, bool tupleIdIsPrimaryKey = false, Type strongRowType = null) |
| 30 | { | 30 | { |
| 31 | this.Name = name; | 31 | this.Name = name; |
| 32 | this.TupleDefinition = tupleDefinition; | 32 | this.TupleDefinition = tupleDefinition; |
| 33 | this.TupleIdIsPrimaryKey = tupleIdIsPrimaryKey; | 33 | this.TupleIdIsPrimaryKey = tupleIdIsPrimaryKey; |
| 34 | this.Unreal = unreal; | 34 | this.Unreal = unreal; |
| 35 | this.Columns = columns?.ToArray(); | 35 | this.Columns = columns?.ToArray(); |
| 36 | this.StrongRowType = strongRowType ?? typeof(Row); | ||
| 36 | 37 | ||
| 37 | if (this.Columns == null || this.Columns.Length == 0) | 38 | if (this.Columns == null || this.Columns.Length == 0) |
| 38 | { | 39 | { |
| 39 | throw new ArgumentOutOfRangeException(nameof(columns)); | 40 | throw new ArgumentOutOfRangeException(nameof(columns)); |
| 40 | } | 41 | } |
| 42 | #if DEBUG | ||
| 43 | if (this.StrongRowType != typeof(Row) && !this.StrongRowType.IsSubclassOf(typeof(Row))) { throw new ArgumentException(nameof(strongRowType)); } | ||
| 44 | #endif | ||
| 41 | } | 45 | } |
| 42 | 46 | ||
| 43 | /// <summary> | 47 | /// <summary> |
| @@ -70,6 +74,8 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 70 | /// <value>Flag if table is unreal.</value> | 74 | /// <value>Flag if table is unreal.</value> |
| 71 | public bool TupleIdIsPrimaryKey { get; } | 75 | public bool TupleIdIsPrimaryKey { get; } |
| 72 | 76 | ||
| 77 | private Type StrongRowType { get; } | ||
| 78 | |||
| 73 | /// <summary> | 79 | /// <summary> |
| 74 | /// Gets the column definition in the table by index. | 80 | /// Gets the column definition in the table by index. |
| 75 | /// </summary> | 81 | /// </summary> |
| @@ -78,6 +84,31 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 78 | public ColumnDefinition this[int columnIndex] => this.Columns[columnIndex]; | 84 | public ColumnDefinition this[int columnIndex] => this.Columns[columnIndex]; |
| 79 | 85 | ||
| 80 | /// <summary> | 86 | /// <summary> |
| 87 | /// In general this method shouldn't be used - create rows from a Table instead. | ||
| 88 | /// Creates a new row object of the type specified in this definition. | ||
| 89 | /// </summary> | ||
| 90 | /// <param name="sourceLineNumbers">Original source lines for this row.</param> | ||
| 91 | /// <returns>Created row.</returns> | ||
| 92 | public Row CreateRow(SourceLineNumber sourceLineNumbers) | ||
| 93 | { | ||
| 94 | var result = (Row)Activator.CreateInstance(this.StrongRowType, sourceLineNumbers, this); | ||
| 95 | return result; | ||
| 96 | } | ||
| 97 | |||
| 98 | /// <summary> | ||
| 99 | /// Creates a new row object of the type specified in this definition for the given table. | ||
| 100 | /// External callers should create the row from the table. | ||
| 101 | /// </summary> | ||
| 102 | /// <param name="sourceLineNumbers">Original source lines for this row.</param> | ||
| 103 | /// <param name="table">The owning table for this row.</param> | ||
| 104 | /// <returns>Created row.</returns> | ||
| 105 | internal Row CreateRow(SourceLineNumber sourceLineNumbers, Table table) | ||
| 106 | { | ||
| 107 | var result = (Row)Activator.CreateInstance(this.StrongRowType, sourceLineNumbers, table); | ||
| 108 | return result; | ||
| 109 | } | ||
| 110 | |||
| 111 | /// <summary> | ||
| 81 | /// Compares this table definition to another table definition. | 112 | /// Compares this table definition to another table definition. |
| 82 | /// </summary> | 113 | /// </summary> |
| 83 | /// <remarks> | 114 | /// <remarks> |
