@@ -133,7 +133,7 @@ public enum VideoFilters
133
133
StereoAdjustment = 0x80
134
134
}
135
135
136
- public struct AspectRatio
136
+ public struct AspectRatio : IEquatable < AspectRatio >
137
137
{
138
138
public static readonly AspectRatio Keep = new ( - 1 , 1 ) ;
139
139
public static readonly AspectRatio Fill = new ( - 2 , 1 ) ;
@@ -173,12 +173,12 @@ public AspectRatio(float value) : this(value, 1) { }
173
173
public AspectRatio ( float num , float den ) { Num = num ; Den = den ; }
174
174
public AspectRatio ( string value ) { Num = Invalid . Num ; Den = Invalid . Den ; FromString ( value ) ; }
175
175
176
- public override bool Equals ( object obj ) => ( obj == null ) || ! GetType ( ) . Equals ( obj . GetType ( ) ) ? false : Num == ( ( AspectRatio ) obj ) . Num && Den == ( ( AspectRatio ) obj ) . Den ;
176
+ public bool Equals ( AspectRatio other ) => Num == other . Num && Den == other . Den ;
177
+ public override bool Equals ( object obj ) => obj is AspectRatio o && Equals ( o ) ;
178
+ public override int GetHashCode ( ) => HashCode . Combine ( Num , Den ) ;
177
179
public static bool operator == ( AspectRatio a , AspectRatio b ) => a . Equals ( b ) ;
178
180
public static bool operator != ( AspectRatio a , AspectRatio b ) => ! ( a == b ) ;
179
181
180
- public override int GetHashCode ( ) => ( int ) ( Value * 1000 ) ;
181
-
182
182
public void FromString ( string value )
183
183
{
184
184
if ( value == "Keep" )
@@ -230,7 +230,7 @@ protected bool Set<T>(ref T field, T value, bool check = true, [CallerMemberName
230
230
{
231
231
//Utils.Log($"[===| {propertyName} |===] | Set | {IsUI()}");
232
232
233
- if ( ! check || ( field == null && value != null ) || ( field != null && ! field . Equals ( value ) ) )
233
+ if ( ! check || ! EqualityComparer < T > . Default . Equals ( field , value ) )
234
234
{
235
235
field = value ;
236
236
@@ -247,7 +247,7 @@ protected bool SetUI<T>(ref T field, T value, bool check = true, [CallerMemberNa
247
247
{
248
248
//Utils.Log($"[===| {propertyName} |===] | SetUI | {IsUI()}");
249
249
250
- if ( ! check || ( field == null && value != null ) || ( field != null && ! field . Equals ( value ) ) )
250
+ if ( ! check || ! EqualityComparer < T > . Default . Equals ( field , value ) )
251
251
{
252
252
field = value ;
253
253
0 commit comments