File tree Expand file tree Collapse file tree 4 files changed +46
-19
lines changed Expand file tree Collapse file tree 4 files changed +46
-19
lines changed Original file line number Diff line number Diff line change 1+ namespace IPConfig . Models ;
2+
3+ /// <summary>
4+ /// 支持深层克隆。
5+ /// </summary>
6+ /// <typeparam name="T"></typeparam>
7+ public interface IDeepCloneable < T >
8+ {
9+ T DeepClone ( ) ;
10+ }
Original file line number Diff line number Diff line change 66
77namespace IPConfig . Models ;
88
9- public abstract partial class IPConfigBase < T > : ObservableValidator , IDeepCloneTo < T > where T : IPConfigBase < T >
9+ public abstract partial class IPConfigBase < T > : ObservableValidator ,
10+ IDeepCloneable < T > , IDeepCloneTo < T > where T : IPConfigBase < T > , new ( )
1011{
1112 protected bool _allowAutoDisableAutoDns ;
1213
@@ -131,7 +132,24 @@ public void AllowAutoDisableDhcp(bool allow = true)
131132 _allowAutoDisableDhcp = allow ;
132133 }
133134
134- public abstract void DeepCloneTo ( T other ) ;
135+ public virtual T DeepClone ( )
136+ {
137+ T clone = new ( ) ;
138+ DeepCloneTo ( clone ) ;
139+
140+ return clone ;
141+ }
142+
143+ public virtual void DeepCloneTo ( T other )
144+ {
145+ other . IP = IP ;
146+ other . IsDhcpEnabled = IsDhcpEnabled ;
147+ other . Mask = Mask ;
148+ other . Gateway = Gateway ;
149+ other . IsAutoDns = IsAutoDns ;
150+ other . Dns1 = Dns1 ;
151+ other . Dns2 = Dns2 ;
152+ }
135153
136154 public virtual void FormatProperties ( )
137155 {
Original file line number Diff line number Diff line change @@ -122,15 +122,9 @@ public void DeepCloneTo(IPConfigModel other)
122122
123123 public bool PropertyEquals ( IPConfigModel other )
124124 {
125- if ( Name == other . Name
126- && IPv4Config . IP == other . IPv4Config . IP
127- && IPv4Config . IsDhcpEnabled == other . IPv4Config . IsDhcpEnabled
128- && IPv4Config . Mask == other . IPv4Config . Mask
129- && IPv4Config . Gateway == other . IPv4Config . Gateway
130- && IPv4Config . IsAutoDns == other . IPv4Config . IsAutoDns
131- && IPv4Config . Dns1 == other . IPv4Config . Dns1
132- && IPv4Config . Dns2 == other . IPv4Config . Dns2
133- && Remark == other . Remark )
125+ bool iPv4ConfigEquals = IPv4Config . PropertyEquals ( other . IPv4Config ) ;
126+
127+ if ( iPv4ConfigEquals && Name == other . Name && Remark == other . Remark )
134128 {
135129 return true ;
136130 }
Original file line number Diff line number Diff line change @@ -40,15 +40,20 @@ public class IPv4Config : IPConfigBase<IPv4Config>
4040 base . ClearErrors ( propertyName ) ;
4141 }
4242
43- public override void DeepCloneTo ( IPv4Config other )
43+ public bool PropertyEquals ( IPv4Config other )
4444 {
45- other . IP = IP ;
46- other . IsDhcpEnabled = IsDhcpEnabled ;
47- other . Mask = Mask ;
48- other . Gateway = Gateway ;
49- other . IsAutoDns = IsAutoDns ;
50- other . Dns1 = Dns1 ;
51- other . Dns2 = Dns2 ;
45+ if ( IP == other . IP
46+ && IsDhcpEnabled == other . IsDhcpEnabled
47+ && Mask == other . Mask
48+ && Gateway == other . Gateway
49+ && IsAutoDns == other . IsAutoDns
50+ && Dns1 == other . Dns1
51+ && Dns2 == other . Dns2 )
52+ {
53+ return true ;
54+ }
55+
56+ return false ;
5257 }
5358
5459 public override string ToString ( )
You can’t perform that action at this time.
0 commit comments