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
|
//------------------------------------------------------------------------------
// <copyright file="Constraint.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
// <owner current="false" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Data {
using System;
using System.ComponentModel;
using System.Globalization;
/// <devdoc>
/// <para>Represents a constraint that can be enforced on one or
/// more <see cref='System.Data.DataColumn'/> objects.</para>
/// </devdoc>
[
DefaultProperty("ConstraintName"),
TypeConverter(typeof(ConstraintConverter))
]
public abstract class Constraint {
internal String name = "";
private String _schemaName = "";
private bool inCollection = false;
private DataSet dataSet = null;
internal PropertyCollection extendedProperties = null;
/// <devdoc>
/// <para>The name of this constraint within the <see cref='System.Data.ConstraintCollection'/>
/// .</para>
/// </devdoc>
[
DefaultValue(""),
ResDescriptionAttribute(Res.ConstraintNameDescr),
ResCategoryAttribute(Res.DataCategory_Data)
]
public virtual string ConstraintName {
get {
return name;
}
set {
if (value == null)
value = "";
if (Common.ADP.IsEmpty(value) && (Table != null) && InCollection)
throw ExceptionBuilder.NoConstraintName();
CultureInfo locale = (Table != null ? Table.Locale : CultureInfo.CurrentCulture);
if (String.Compare(name, value, true, locale) != 0) {
if ((Table != null) && InCollection) {
Table.Constraints.RegisterName(value);
if (name.Length != 0)
Table.Constraints.UnregisterName(name);
}
name = value;
}
else if (String.Compare(name, value, false, locale) != 0) {
name = value;
}
}
}
internal String SchemaName {
get {
if (Common.ADP.IsEmpty(_schemaName))
return ConstraintName;
else
return _schemaName;
}
set {
if (!Common.ADP.IsEmpty(value))
_schemaName = value;
}
}
internal virtual bool InCollection {
get { // ACCESSOR: virtual was missing from this get
return inCollection;
}
set {
inCollection = value;
if (value)
dataSet = Table.DataSet;
else
dataSet = null;
}
}
/// <devdoc>
/// <para>Gets the <see cref='System.Data.DataTable'/> to which the constraint applies.</para>
/// </devdoc>
[ResDescriptionAttribute(Res.ConstraintTableDescr)]
public abstract DataTable Table {
get;
}
/// <devdoc>
/// <para>Gets the collection of customized user information.</para>
/// </devdoc>
[
ResCategoryAttribute(Res.DataCategory_Data),
Browsable(false),
ResDescriptionAttribute(Res.ExtendedPropertiesDescr)
]
public PropertyCollection ExtendedProperties {
get {
if (extendedProperties == null) {
extendedProperties = new PropertyCollection();
}
return extendedProperties;
}
}
internal abstract bool ContainsColumn(DataColumn column);
internal abstract bool CanEnableConstraint();
internal abstract Constraint Clone(DataSet destination);
internal abstract Constraint Clone(DataSet destination, bool ignoreNSforTableLookup);
internal void CheckConstraint() {
if (!CanEnableConstraint()) {
throw ExceptionBuilder.ConstraintViolation(ConstraintName);
}
}
internal abstract void CheckCanAddToCollection(ConstraintCollection constraint);
internal abstract bool CanBeRemovedFromCollection(ConstraintCollection constraint, bool fThrowException);
internal abstract void CheckConstraint(DataRow row, DataRowAction action);
internal abstract void CheckState();
protected void CheckStateForProperty() {
try {
CheckState();
}
catch (Exception e) {
//
if (!Common.ADP.IsCatchableExceptionType (e)) {
throw;
}
throw ExceptionBuilder.BadObjectPropertyAccess(e.Message);
}
}
/// <devdoc>
/// <para>Gets the <see cref='System.Data.DataSet'/> to which this constraint belongs.</para>
/// </devdoc>
[CLSCompliant(false)]
protected virtual DataSet _DataSet {
get {
return dataSet;
}
}
/// <devdoc>
/// <para>Sets the constraint's <see cref='System.Data.DataSet'/>.</para>
/// </devdoc>
protected internal void SetDataSet(DataSet dataSet) {
this.dataSet = dataSet;
}
internal abstract bool IsConstraintViolated();
public override string ToString() {
return ConstraintName;
}
}
}
|