@@ -15,7 +15,7 @@ namespace Datamodel
1515 [ TypeConverter ( typeof ( TypeConverters . ElementConverter ) ) ]
1616 [ DebuggerTypeProxy ( typeof ( AttributeList . DebugView ) ) ]
1717 [ DebuggerDisplay ( "{Name} {ID}" , Type = "{ClassName,nq}" ) ]
18- public class Element : AttributeList , INotifyPropertyChanged , ISupportInitialize
18+ public class Element : AttributeList , IEquatable < Element >
1919 {
2020 #region Constructors and Init
2121
@@ -36,11 +36,11 @@ public Element(Datamodel owner, string name, Guid? id = null, string classNameOv
3636 ClassName = classNameOverride ?? ClassName ;
3737
3838 if ( id . HasValue )
39- _ID = id . Value ;
39+ ID = id . Value ;
4040 else
4141 {
4242 if ( ! owner . AllowRandomIDs ) throw new InvalidOperationException ( "Random IDs are not allowed in this Datamodel." ) ;
43- _ID = Guid . NewGuid ( ) ;
43+ ID = Guid . NewGuid ( ) ;
4444 }
4545 Owner = owner ;
4646 }
@@ -56,7 +56,7 @@ public Element(Datamodel owner, Guid id)
5656 {
5757 ArgumentNullException . ThrowIfNull ( owner ) ;
5858
59- _ID = id ;
59+ ID = id ;
6060 Stub = true ;
6161 Name = "Stub element" ;
6262 Owner = owner ;
@@ -68,7 +68,7 @@ public Element(Datamodel owner, Guid id)
6868 public Element ( )
6969 : base ( null )
7070 {
71- _ID = Guid . NewGuid ( ) ;
71+ ID = Guid . NewGuid ( ) ;
7272
7373 // For subclasses get the actual classname
7474 if ( GetType ( ) != typeof ( Element ) )
@@ -84,39 +84,14 @@ public Element()
8484 }
8585 }
8686
87- bool Initialising = false ;
88- void ISupportInitialize . BeginInit ( )
89- {
90- Initialising = true ;
91- }
92-
93- void ISupportInitialize . EndInit ( )
94- {
95- if ( ID == default )
96- {
97- ID = Guid . NewGuid ( ) ;
98- }
99-
100- Initialising = false ;
101- }
102-
10387 #endregion
10488
10589 #region Properties
10690
10791 /// <summary>
10892 /// Gets the ID of this Element. This must be unique within the Element's <see cref="Datamodel"/>.
10993 /// </summary>
110- public Guid ID
111- {
112- get => _ID ;
113- set
114- {
115- if ( ! Initialising && value != _ID ) throw new InvalidOperationException ( "ID can only be changed during initialisation." ) ;
116- _ID = value ;
117- }
118- }
119- Guid _ID ;
94+ public Guid ID { get ; set ; }
12095
12196 /// <summary>
12297 /// Gets or sets the name of this Element.
@@ -402,6 +377,11 @@ public override bool ContainsKey(string key)
402377 if ( Stub ) throw new InvalidOperationException ( "Cannot access attributes on a stub element." ) ;
403378 return base . ContainsKey ( key ) ;
404379 }
380+
381+ public bool Equals ( Element other )
382+ {
383+ return other != null && ID == other . ID ;
384+ }
405385 }
406386
407387 namespace TypeConverters
0 commit comments