forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameterTemplate.cs
More file actions
121 lines (104 loc) · 3.18 KB
/
ParameterTemplate.cs
File metadata and controls
121 lines (104 loc) · 3.18 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
using System;
using System.Data;
namespace Simple.Data.Ado
{
using Schema;
public class ParameterTemplate : IEquatable<ParameterTemplate>
{
private readonly object _fixedValue;
private readonly string _name;
private readonly DbType _dbType;
private readonly int _maxLength;
private readonly Column _column;
private readonly ParameterType _type;
public ParameterTemplate(string name, object fixedValue)
: this(name, null)
{
_fixedValue = fixedValue;
_type = ParameterType.FixedValue;
}
public ParameterTemplate(string name, Column column)
{
if (name == null) throw new ArgumentNullException("name");
_name = name;
_column = column;
if (column == null)
{
_type = ParameterType.NameOnly;
return;
}
_type = ParameterType.Column;
_dbType = column.DbType;
_maxLength = column.MaxLength;
}
public ParameterTemplate(string name, DbType dbType, int maxLength)
{
if (name == null) throw new ArgumentNullException("name");
_name = name;
_dbType = dbType;
_maxLength = maxLength;
_type = ParameterType.Other;
}
internal ParameterType Type
{
get { return _type; }
}
public int MaxLength
{
get { return _maxLength; }
}
public DbType DbType
{
get { return _dbType; }
}
public string Name
{
get { return _name; }
}
public Column Column
{
get { return _column; }
}
public object FixedValue
{
get { return _fixedValue; }
}
public ParameterTemplate Rename(string newName)
{
return _column == null
? new ParameterTemplate(newName, _dbType, _maxLength)
: new ParameterTemplate(newName, _column);
}
public bool Equals(ParameterTemplate other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other._name, _name) && Equals(other._dbType, _dbType);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (ParameterTemplate)) return false;
return Equals((ParameterTemplate) obj);
}
public override int GetHashCode()
{
unchecked
{
return (_name.GetHashCode()*397) ^ _dbType.GetHashCode();
}
}
public override string ToString()
{
return Name;
}
}
internal enum ParameterType
{
Column,
FixedValue,
Other,
NameOnly
}
}