2 // System.Data.Constraint.cs
5 // Franklin Wise <gracenote@earthlink.net>
9 // (C) Ximian, Inc. 2002
13 using System.Collections;
14 using System.ComponentModel;
15 using System.Runtime.InteropServices;
16 using System.Runtime.Serialization;
21 internal delegate void DelegateConstraintNameChange(object sender,
25 public abstract class Constraint
27 internal event DelegateConstraintNameChange
28 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;
41 protected Constraint()
43 _properties = new PropertyCollection();
46 public virtual string ConstraintName {
48 return "" + _constraintName;
52 //This should only throw an exception when it
53 //is a member of a ConstraintCollection which
54 //means we should let the ConstraintCollection
55 //handle exceptions when this value changes
56 _onConstraintNameChange(value);
57 _constraintName = value;
61 public PropertyCollection ExtendedProperties {
67 public abstract DataTable Table {
72 /// Gets the ConstraintName, if there is one, as a string.
74 public override string ToString()
76 return "" + _constraintName;
79 internal ConstraintCollection ConstraintCollection {
81 return _constraintCollection;
84 _constraintCollection = value;
89 private void _onConstraintNameChange(string newName)
91 if (null != BeforeConstraintNameChange)
93 BeforeConstraintNameChange(this, newName);
97 //call once before adding a constraint to a collection
98 //will throw an exception to prevent the add if a rule is broken
99 internal virtual void AddToConstraintCollectionSetup(
100 ConstraintCollection collection){}
102 //call once before removing a constraint to a collection
103 //can throw an exception to prevent the removal
104 internal virtual void RemoveFromConstraintCollectionCleanup(
105 ConstraintCollection collection){}
107 internal virtual void AssertConstraint(){}
109 internal virtual void AssertConstraint(DataRow row){}