16b85f3a23df01668d48502b1e7e36691af9756c
[mono.git] / mcs / class / referencesource / System.Data / System / Data / SqlClient / SqlBulkCopyColumnMapping.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="SqlBulkCopyColumnMapping.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8
9 // Todo: rename the file
10 // Caution! ndp\fx\src\data\netmodule\sources needs to follow this change
11
12 namespace System.Data.SqlClient
13 {
14     using System;
15     using System.Data;
16     using System.Data.Common;
17     using System.Data.SqlTypes;
18     using System.ComponentModel;
19
20     using System.Collections;
21     using System.Diagnostics;
22
23     // -------------------------------------------------------------------------------------------------
24     // this class helps allows the user to create association between source- and targetcolumns
25     //
26     //
27
28     public sealed class SqlBulkCopyColumnMapping {
29         internal string         _destinationColumnName;
30         internal int            _destinationColumnOrdinal;
31         internal string         _sourceColumnName;
32         internal int            _sourceColumnOrdinal;
33
34         // devnote: we don't want the user to detect the columnordinal after WriteToServer call.
35         // _sourceColumnOrdinal(s) will be copied to _internalSourceColumnOrdinal when WriteToServer executes.
36         internal int            _internalDestinationColumnOrdinal;
37         internal int            _internalSourceColumnOrdinal;   // -1 indicates an undetermined value
38
39         public string DestinationColumn {
40             get {
41                 if (_destinationColumnName != null) {
42                     return _destinationColumnName;
43                 }
44                 return string.Empty;
45             }
46             set {
47                 _destinationColumnOrdinal = _internalDestinationColumnOrdinal = -1;
48                 _destinationColumnName = value;
49             }
50         }
51
52         public int DestinationOrdinal {
53             get {
54                     return _destinationColumnOrdinal;
55             }
56             set {
57                 if (value >= 0) {
58                     _destinationColumnName = null;
59                     _destinationColumnOrdinal = _internalDestinationColumnOrdinal = value;
60                 }
61                 else {
62                     throw ADP.IndexOutOfRange(value);
63                 }
64             }
65         }
66
67         public string SourceColumn {
68             get {
69                 if (_sourceColumnName != null) {
70                     return _sourceColumnName;
71                 }
72                 return string.Empty;
73             }
74             set {
75                 _sourceColumnOrdinal = _internalSourceColumnOrdinal = -1;
76                 _sourceColumnName = value;
77             }
78         }
79
80         public int SourceOrdinal {
81             get {
82                     return _sourceColumnOrdinal;
83             }
84             set {
85                 if (value >= 0) {
86                     _sourceColumnName = null;
87                     _sourceColumnOrdinal = _internalSourceColumnOrdinal = value;
88                 }
89                 else {
90                     throw ADP.IndexOutOfRange(value);
91                 }
92             }
93         }
94
95         public SqlBulkCopyColumnMapping () {
96             _internalSourceColumnOrdinal = -1;
97         }
98
99         public SqlBulkCopyColumnMapping (string sourceColumn, string destinationColumn) {
100             SourceColumn = sourceColumn;
101             DestinationColumn = destinationColumn;
102         }
103
104         public SqlBulkCopyColumnMapping (int sourceColumnOrdinal, string destinationColumn) {
105             SourceOrdinal = sourceColumnOrdinal;
106             DestinationColumn = destinationColumn;
107         }
108
109         public SqlBulkCopyColumnMapping (string sourceColumn, int destinationOrdinal) {
110             SourceColumn = sourceColumn;
111             DestinationOrdinal = destinationOrdinal;
112         }
113
114         public SqlBulkCopyColumnMapping (int sourceColumnOrdinal, int destinationOrdinal) {
115             SourceOrdinal = sourceColumnOrdinal;
116             DestinationOrdinal = destinationOrdinal;
117         }
118     }
119 }