整理代码
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using ShrlAlgo.RvKits.RvIndependent.MetroGauges.LandXMLData.Interfaces;
|
||||
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace ShrlAlgo.RvKits.RvIndependent.MetroGauges.LandXMLData;
|
||||
|
||||
[XmlType("Range")]
|
||||
[Serializable]
|
||||
public class Range : GenerationRangeInstance, IComparableStructure<Range>
|
||||
{
|
||||
public Range()
|
||||
{
|
||||
StartStation = 0.0;
|
||||
EndStation = 0.0;
|
||||
Part = 0;
|
||||
Import = true;
|
||||
}
|
||||
|
||||
protected bool _import;
|
||||
|
||||
protected Part _parent;
|
||||
|
||||
[XmlIgnore]
|
||||
public string NameSideSegment => Parent == null ? string.Empty : Parent.NameSideSegment;
|
||||
|
||||
[XmlIgnore]
|
||||
public string NameSideSegmentPart => Parent == null ? PartName : NameSideSegment + PartName;
|
||||
|
||||
[XmlIgnore]
|
||||
public Part Parent
|
||||
{
|
||||
get => _parent;
|
||||
internal set
|
||||
{
|
||||
if (_parent != value)
|
||||
{
|
||||
_parent = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public string PartName => Part == 0 ? string.Empty : " p" + Part;
|
||||
|
||||
[XmlIgnore]
|
||||
public IEnumerable<DesignShape> Shapes => Parent == null ? null : Parent.Shapes;
|
||||
|
||||
[XmlAttribute]
|
||||
public bool Import
|
||||
{
|
||||
get => _import;
|
||||
set => _import = value;
|
||||
}
|
||||
|
||||
[XmlAttribute("p")]
|
||||
public int Part { get; set; }
|
||||
|
||||
public bool DifferentDescendants(Range range)
|
||||
{
|
||||
IEnumerable<DesignShape> shapes = Shapes;
|
||||
IEnumerable<DesignShape> shapes2 = range.Shapes;
|
||||
if (shapes == null || shapes2 == null)
|
||||
{
|
||||
return shapes != shapes2;
|
||||
}
|
||||
|
||||
DesignShape[] array = shapes.ToArray();
|
||||
DesignShape[] array2 = shapes2.ToArray();
|
||||
if (array.Length == array2.Length)
|
||||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (!array[i].Equals(array2[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DifferentItem(Range range)
|
||||
{
|
||||
return Import != range.Import
|
||||
|| StartStation != range.StartStation
|
||||
|| EndStation != range.EndStation
|
||||
|| GenerationStartStation != range.GenerationStartStation
|
||||
|| GenerationEndStation != range.GenerationEndStation;
|
||||
}
|
||||
|
||||
public bool Equals(Range range)
|
||||
{
|
||||
return range is not null && !DifferentItem(range) && !DifferentDescendants(range);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as Range);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public void SetParent(Part part)
|
||||
{
|
||||
if (_parent != part)
|
||||
{
|
||||
_parent?.Ranges.Remove(this);
|
||||
|
||||
_parent = part;
|
||||
_parent?.AddRange(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user