@@ -15,7 +15,7 @@ namespace Datamodel
15
15
[ TypeConverter ( typeof ( TypeConverters . ElementConverter ) ) ]
16
16
[ DebuggerTypeProxy ( typeof ( AttributeList . DebugView ) ) ]
17
17
[ DebuggerDisplay ( "{Name} {ID}" , Type = "{ClassName,nq}" ) ]
18
- public class Element : AttributeList , INotifyPropertyChanged , ISupportInitialize
18
+ public class Element : AttributeList , IEquatable < Element >
19
19
{
20
20
#region Constructors and Init
21
21
@@ -36,11 +36,11 @@ public Element(Datamodel owner, string name, Guid? id = null, string classNameOv
36
36
ClassName = classNameOverride ?? ClassName ;
37
37
38
38
if ( id . HasValue )
39
- _ID = id . Value ;
39
+ ID = id . Value ;
40
40
else
41
41
{
42
42
if ( ! owner . AllowRandomIDs ) throw new InvalidOperationException ( "Random IDs are not allowed in this Datamodel." ) ;
43
- _ID = Guid . NewGuid ( ) ;
43
+ ID = Guid . NewGuid ( ) ;
44
44
}
45
45
Owner = owner ;
46
46
}
@@ -56,7 +56,7 @@ public Element(Datamodel owner, Guid id)
56
56
{
57
57
ArgumentNullException . ThrowIfNull ( owner ) ;
58
58
59
- _ID = id ;
59
+ ID = id ;
60
60
Stub = true ;
61
61
Name = "Stub element" ;
62
62
Owner = owner ;
@@ -68,7 +68,7 @@ public Element(Datamodel owner, Guid id)
68
68
public Element ( )
69
69
: base ( null )
70
70
{
71
- _ID = Guid . NewGuid ( ) ;
71
+ ID = Guid . NewGuid ( ) ;
72
72
73
73
// For subclasses get the actual classname
74
74
if ( GetType ( ) != typeof ( Element ) )
@@ -84,39 +84,14 @@ public Element()
84
84
}
85
85
}
86
86
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
-
103
87
#endregion
104
88
105
89
#region Properties
106
90
107
91
/// <summary>
108
92
/// Gets the ID of this Element. This must be unique within the Element's <see cref="Datamodel"/>.
109
93
/// </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 ; }
120
95
121
96
/// <summary>
122
97
/// Gets or sets the name of this Element.
@@ -402,6 +377,11 @@ public override bool ContainsKey(string key)
402
377
if ( Stub ) throw new InvalidOperationException ( "Cannot access attributes on a stub element." ) ;
403
378
return base . ContainsKey ( key ) ;
404
379
}
380
+
381
+ public bool Equals ( Element other )
382
+ {
383
+ return other != null && ID == other . ID ;
384
+ }
405
385
}
406
386
407
387
namespace TypeConverters
0 commit comments