ningshuxia
2024-06-18 e83dca6e861b622b54d3392ca0d3f1f1eb69f7c9
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
namespace IStation.Epanet.Network.Structures
{
 
    public enum ElementType { NODE, LINK, PATTERN, CURVE, CONTROL, RULE }
 
    /// <summary>Base class for all IStation.Epanet elements - Links, Nodes etc.</summary>
    public abstract class Element : IComparable<Element>, IEquatable<Element>
    {
        private readonly string _name;
        protected Element(string name)
        {
            if (name == null)
                throw new ArgumentNullException(nameof(name));
 
            if (name.Length == 0 || name.Length > Constants.MAXID)
                throw new ArgumentException(nameof(name));
 
            _name = name;
        }
        public abstract ElementType ElementType { get; }
 
        public string Name => _name;
 
        public string Tag { get; set; } = string.Empty;
 
        /// <summary>Element comment (parsed from INP or excel file)</summary>
        public string Comment { get; set; }
 
        #region Overrides of Object
 
        public override string ToString()
        {
            return string.Format("{0}{{{1}}}", GetType().Name, _name);
        }
 
        #endregion
 
        #region Implementation of IComparable<Element>, IEquatable<Element>
 
        public int CompareTo(Element other)
        {
            return other == null ? 1 : string.Compare(Name, other.Name, StringComparison.OrdinalIgnoreCase);
        }
 
        public bool Equals(Element other)
        {
            return other != null && string.Equals(_name, other._name, StringComparison.OrdinalIgnoreCase);
        }
 
        public override int GetHashCode()
        {
            return string.IsNullOrEmpty(_name)
                ? 0
                : _name.GetHashCode();
        }
 
        #endregion
 
 
    }
 
}