blob: e25bb52cf092494fac8f0a9719a0bf81012945ba (
plain)
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
|
//
// System.Data.Common.DataColumnMapping
//
// Authors:
// Rodrigo Moya (rodrigo@ximian.com)
// Tim Coleman (tim@timcoleman.com)
//
// (C) Ximian, Inc
// Copyright (C) Tim Coleman, 2002
//
using System.ComponentModel;
using System.Data;
namespace System.Data.Common {
public sealed class DataColumnMapping : MarshalByRefObject, IColumnMapping, ICloneable
{
#region Fields
string sourceColumn;
string dataSetColumn;
#endregion // Fields
#region Constructors
public DataColumnMapping ()
{
sourceColumn = String.Empty;
dataSetColumn = String.Empty;
}
public DataColumnMapping (string sourceColumn, string dataSetColumn)
{
this.sourceColumn = sourceColumn;
this.dataSetColumn = dataSetColumn;
}
#endregion // Constructors
#region Properties
[DataSysDescription ("DataColumn.ColumnName")]
[DefaultValue ("")]
public string DataSetColumn {
get { return dataSetColumn; }
set { dataSetColumn = value; }
}
[DataSysDescription ("Source column name - case sensitive.")]
[DefaultValue ("")]
public string SourceColumn {
get { return sourceColumn; }
set { sourceColumn = value; }
}
#endregion // Properties
#region Methods
[EditorBrowsable (EditorBrowsableState.Advanced)]
public DataColumn GetDataColumnBySchemaAction (DataTable dataTable, Type dataType, MissingSchemaAction schemaAction)
{
if (dataTable.Columns.Contains (dataSetColumn))
return dataTable.Columns [dataSetColumn];
if (schemaAction == MissingSchemaAction.Ignore)
return null;
if (schemaAction == MissingSchemaAction.Error)
throw new InvalidOperationException (String.Format ("Missing the DataColumn '{0}' in the DataTable '{1}' for the SourceColumn '{2}'", DataSetColumn, dataTable.TableName, SourceColumn));
return new DataColumn (dataSetColumn, dataType);
}
object ICloneable.Clone ()
{
return new DataColumnMapping (SourceColumn, DataSetColumn);
}
public override string ToString ()
{
return SourceColumn;
}
#endregion // Methods
}
}
|