File: DbParameterHelper.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (256 lines) | stat: -rw-r--r-- 7,928 bytes parent folder | download | duplicates (6)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//---------------------------------------------------------------------
// <copyright file="DbParameterHelper.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner  Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------


namespace System.Data.EntityClient {

    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Data.Common;
    using System.Data.Entity;

    public sealed partial class EntityParameter : DbParameter { 
        private object _value;

        private object _parent;

        private ParameterDirection _direction;
        private int? _size;


        private string _sourceColumn;
        private DataRowVersion _sourceVersion;
        private bool _sourceColumnNullMapping;

        private bool? _isNullable;

        private object _coercedValue;

        private EntityParameter(EntityParameter source) : this() { 
            EntityUtil.CheckArgumentNull(source, "source");

            source.CloneHelper(this);

            ICloneable cloneable = (_value as ICloneable);
            if (null != cloneable) { 
                _value = cloneable.Clone();
            }
        }

        private object CoercedValue { 
            get {
                return _coercedValue;
            }
            set {
                _coercedValue = value;
            }
        }

        [
        RefreshProperties(RefreshProperties.All),
        EntityResCategoryAttribute(EntityRes.DataCategory_Data),
        EntityResDescriptionAttribute(EntityRes.DbParameter_Direction),
        ]
        override public ParameterDirection Direction { 
            get {
                ParameterDirection direction = _direction;
                return ((0 != direction) ? direction : ParameterDirection.Input);
            }
            set {
                if (_direction != value) {
                    switch (value) { 
                    case ParameterDirection.Input:
                    case ParameterDirection.Output:
                    case ParameterDirection.InputOutput:
                    case ParameterDirection.ReturnValue:
                        PropertyChanging();
                        _direction = value;
                        break;
                    default:
                        throw EntityUtil.InvalidParameterDirection(value);
                    }
                }
            }
        }

        override public bool IsNullable { 
            get {
                bool result = this._isNullable.HasValue ? this._isNullable.Value : true;
                return result;
            }
            set {
                _isNullable = value;
            }
        }

        internal int Offset {
            get {
                return 0;
            }
        }

        [
        EntityResCategoryAttribute(EntityRes.DataCategory_Data),
        EntityResDescriptionAttribute(EntityRes.DbParameter_Size),
        ]
        override public int Size { 
            get {
                int size = _size.HasValue ? _size.Value : 0;
                if (0 == size) {
                    size = ValueSize(Value);
                }
                return size;
            }
            set {
                if (!_size.HasValue || _size.Value != value) {
                    if (value < -1) {
                        throw EntityUtil.InvalidSizeValue(value);
                    }
                    PropertyChanging();
                    if (0 == value) {
                        _size = null;
                    }
                    else {
                        _size = value;
                    }
                }
            }
        }

        private void ResetSize() {
            if (_size.HasValue) {
                PropertyChanging();
                _size = null;
            }
        }

        private bool ShouldSerializeSize() { 
            return (_size.HasValue && _size.Value != 0);
        }

        [
        EntityResCategoryAttribute(EntityRes.DataCategory_Update),
        EntityResDescriptionAttribute(EntityRes.DbParameter_SourceColumn),
        ]
        override public string SourceColumn { 
            get {
                string sourceColumn = _sourceColumn;
                return ((null != sourceColumn) ? sourceColumn : string.Empty);
            }
            set {
                _sourceColumn = value;
            }
        }

        public override bool SourceColumnNullMapping {
            get {
                return _sourceColumnNullMapping;
            }
            set {
                _sourceColumnNullMapping = value;
            }
        }

        [
        EntityResCategoryAttribute(EntityRes.DataCategory_Update),
        EntityResDescriptionAttribute(EntityRes.DbParameter_SourceVersion),
        ]
        override public DataRowVersion SourceVersion { 
            get {
                DataRowVersion sourceVersion = _sourceVersion;
                return ((0 != sourceVersion) ? sourceVersion : DataRowVersion.Current);
            }
            set {
                switch(value) { 
                case DataRowVersion.Original:
                case DataRowVersion.Current:
                case DataRowVersion.Proposed:
                case DataRowVersion.Default:
                    _sourceVersion = value;
                    break;
                default:
                    throw EntityUtil.InvalidDataRowVersion(value);
                }
            }
        }

        private void CloneHelperCore(EntityParameter destination) {
            destination._value                     = _value;
            
            destination._direction                 = _direction;
            destination._size                      = _size;

            destination._sourceColumn              = _sourceColumn;
            destination._sourceVersion             = _sourceVersion;
            destination._sourceColumnNullMapping   = _sourceColumnNullMapping;
            destination._isNullable                = _isNullable;
        }
        
        internal void CopyTo(DbParameter destination) {
            EntityUtil.CheckArgumentNull(destination, "destination");
            CloneHelper((EntityParameter)destination);
        }

        internal object CompareExchangeParent(object value, object comparand) {
            
            
            
            
            object parent = _parent;
            if (comparand == parent) {
                _parent = value;
            }
            return parent;
        }

        internal void ResetParent() {
            _parent = null;
        }

        override public string ToString() { 
            return ParameterName;
        }

        private byte ValuePrecisionCore(object value) { 
            if (value is Decimal) {
                return ((System.Data.SqlTypes.SqlDecimal)(Decimal) value).Precision; 
            }
            return 0;
        }

        private  byte ValueScaleCore(object value) { 
            if (value is Decimal) {
                return (byte)((Decimal.GetBits((Decimal)value)[3] & 0x00ff0000) >> 0x10);
            }
            return 0;
        }

        private  int ValueSizeCore(object value) { 
            if (!EntityUtil.IsNull(value)) {
                string svalue = (value as string);
                if (null != svalue) {
                    return svalue.Length;
                }
                byte[] bvalue = (value as byte[]);
                if (null != bvalue) {
                    return bvalue.Length;
                }
                char[] cvalue = (value as char[]);
                if (null != cvalue) {
                    return cvalue.Length;
                }
                if ((value is byte) || (value is char)) {
                    return 1;
                }
            }
            return 0;
        }
    }
}