forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColumn.cs
More file actions
126 lines (109 loc) · 4.03 KB
/
Column.cs
File metadata and controls
126 lines (109 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Data;
using Simple.Data.Extensions;
namespace Simple.Data.Ado.Schema
{
public class Column : IEquatable<Column>
{
private readonly string _actualName;
private readonly Table _table;
private readonly bool _isIdentity;
private readonly DbType _dbType;
private readonly int _maxLength;
public Column(string actualName, Table table) : this(actualName, table, DbType.Object)
{
}
public Column(string actualName, Table table, DbType dbType) : this(actualName, table, false, dbType, 0)
{
}
public Column(string actualName, Table table, bool isIdentity) : this(actualName, table, isIdentity, DbType.Object, 0)
{
}
public Column(string actualName, Table table, bool isIdentity, DbType dbType, int maxLength)
{
_actualName = actualName;
_dbType = dbType;
_maxLength = maxLength;
_isIdentity = isIdentity;
_table = table;
}
public int MaxLength
{
get { return _maxLength; }
}
public DbType DbType
{
get { return _dbType; }
}
public string HomogenizedName
{
get { return ActualName.Homogenize(); }
}
public string ActualName
{
get { return _actualName; }
}
public string QuotedName
{
get { return _table.DatabaseSchema.QuoteObjectName(_actualName); }
}
public string QualifiedName
{
get { return _table.QualifiedName + "." + QuotedName; }
}
public bool IsIdentity
{
get { return _isIdentity; }
}
public virtual bool IsWriteable
{
get { return !IsIdentity; }
}
public virtual bool IsBinary
{
get { return _dbType == DbType.Binary; }
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public bool Equals(Column other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other._actualName, _actualName) && Equals(other._table, _table);
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
/// </returns>
/// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. </param><filterpriority>2</filterpriority>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (Column)) return false;
return Equals((Column) obj);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object"/>.
/// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode()
{
unchecked
{
return ((_actualName != null ? _actualName.GetHashCode() : 0)*397) ^ (_table != null ? _table.GetHashCode() : 0);
}
}
}
}