Skip to content

Commit 0ae402e

Browse files
committed
Code optimization
1 parent 4b70325 commit 0ae402e

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/Sql/Reflection/ColumnInfo.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ namespace Belin.Sql.Reflection;
66
/// <summary>
77
/// Provides information about a database column.
88
/// </summary>
9-
/// <param name="property">The property information providing the column metadata.</param>
10-
public sealed class ColumnInfo(PropertyInfo property) {
9+
public sealed class ColumnInfo {
1110

1211
/// <summary>
1312
/// The nullability context.
@@ -27,38 +26,46 @@ public sealed class ColumnInfo(PropertyInfo property) {
2726
/// <summary>
2827
/// Value indicating whether the column value is generated by the database.
2928
/// </summary>
30-
public bool IsComputed => databaseGeneratedOption != DatabaseGeneratedOption.None;
29+
public bool IsComputed { get; }
3130

3231
/// <summary>
3332
/// Value indicating whether the column value is generated by the database when a row is inserted.
3433
/// </summary>
35-
public bool IsIdentity => databaseGeneratedOption == DatabaseGeneratedOption.Identity;
34+
public bool IsIdentity { get; }
3635

3736
/// <summary>
3837
/// Value indicating whether the column value is nullable.
3938
/// </summary>
40-
public bool IsNullable => Nullable.GetUnderlyingType(Type) is not null || nullability.WriteState != NullabilityState.NotNull;
39+
public bool IsNullable { get; }
4140

4241
/// <summary>
4342
/// The column name.
4443
/// </summary>
45-
public string Name { get; } = property.GetCustomAttribute<ColumnAttribute>()?.Name ?? property.Name;
44+
public string Name { get; }
4645

4746
/// <summary>
4847
/// The type of the column value.
4948
/// </summary>
5049
public Type Type => property.PropertyType;
5150

5251
/// <summary>
53-
/// Value indicating how the database generates values for this column.
52+
/// The property information providing the column metadata.
5453
/// </summary>
55-
private readonly DatabaseGeneratedOption databaseGeneratedOption =
56-
property.GetCustomAttribute<DatabaseGeneratedAttribute>()?.DatabaseGeneratedOption ?? DatabaseGeneratedOption.None;
54+
private readonly PropertyInfo property;
5755

5856
/// <summary>
59-
/// The nullability information for the underlying property.
57+
/// Creates new column information.
6058
/// </summary>
61-
private readonly NullabilityInfo nullability = nullabilityContext.Create(property);
59+
/// <param name="property">The property information providing the column metadata.</param>
60+
public ColumnInfo(PropertyInfo property) {
61+
this.property = property;
62+
63+
var databaseGeneratedOption = property.GetCustomAttribute<DatabaseGeneratedAttribute>()?.DatabaseGeneratedOption ?? DatabaseGeneratedOption.None;
64+
IsComputed = databaseGeneratedOption != DatabaseGeneratedOption.None;
65+
IsIdentity = databaseGeneratedOption == DatabaseGeneratedOption.Identity;
66+
IsNullable = Nullable.GetUnderlyingType(property.PropertyType) is not null || nullabilityContext.Create(property).WriteState != NullabilityState.NotNull;
67+
Name = property.GetCustomAttribute<ColumnAttribute>()?.Name ?? property.Name;
68+
}
6269

6370
/// <summary>
6471
/// Gets the property value of a specified object.

src/Sql/Reflection/TableInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace Belin.Sql.Reflection;
77
/// <summary>
88
/// Provides information about a database table.
99
/// </summary>
10-
/// <param name="type">The type information providing the table metadata.</param>
1110
public sealed class TableInfo {
1211

1312
/// <summary>

0 commit comments

Comments
 (0)