2 // System.Data.Constraint.cs
5 // Franklin Wise <gracenote@earthlink.net>
7 // Tim Coleman (tim@timcoleman.com)
10 // (C) Ximian, Inc. 2002
11 // Copyright (C) Tim Coleman, 2002
15 using System.Collections;
16 using System.ComponentModel;
17 using System.Runtime.InteropServices;
18 using System.Runtime.Serialization;
20 namespace System.Data {
22 internal delegate void DelegateConstraintNameChange (object sender, string newName);
24 [DefaultProperty ("ConstraintName")]
26 public abstract class Constraint
28 internal event DelegateConstraintNameChange BeforeConstraintNameChange;
30 //if constraintName is not set then a name is
31 //created when it is added to
32 //the ConstraintCollection
33 //it can not be set to null, empty or duplicate
34 //once it has been added to the collection
35 private string _constraintName = null;
36 private PropertyCollection _properties = null;
38 //Used for membership checking
39 private ConstraintCollection _constraintCollection;
43 protected Constraint ()
46 _properties = new PropertyCollection();
49 protected internal virtual DataSet _DataSet {
50 get { return dataSet; }
53 [DataCategory ("Data")]
54 [DataSysDescription ("Indicates the name of this constraint.")]
56 public virtual string ConstraintName {
57 get{ return "" + _constraintName; }
59 //This should only throw an exception when it
60 //is a member of a ConstraintCollection which
61 //means we should let the ConstraintCollection
62 //handle exceptions when this value changes
63 _onConstraintNameChange(value);
64 _constraintName = value;
69 [DataCategory ("Data")]
70 [DataSysDescription ("The collection that holds custom user information.")]
71 public PropertyCollection ExtendedProperties {
72 get { return _properties; }
75 [DataSysDescription ("Indicates the table of this constraint.")]
76 public abstract DataTable Table {
80 internal ConstraintCollection ConstraintCollection {
81 get{ return _constraintCollection; }
82 set{ _constraintCollection = value; }
85 private void _onConstraintNameChange (string newName)
87 if (null != BeforeConstraintNameChange)
89 BeforeConstraintNameChange (this, newName);
93 //call once before adding a constraint to a collection
94 //will throw an exception to prevent the add if a rule is broken
95 internal virtual void AddToConstraintCollectionSetup (ConstraintCollection collection)
99 internal virtual void AssertConstraint ()
103 internal virtual void AssertConstraint (DataRow row)
107 //call once before removing a constraint to a collection
108 //can throw an exception to prevent the removal
109 internal virtual void RemoveFromConstraintCollectionCleanup (ConstraintCollection collection)
114 protected void CheckStateForProperty ()
116 throw new NotImplementedException ();
119 protected internal void SetDataSet (DataSet dataSet)
121 this.dataSet = dataSet;
125 /// Gets the ConstraintName, if there is one, as a string.
127 public override string ToString ()
129 return "" + _constraintName;