Skip to content

Commit 8233e6b

Browse files
authored
Simplify conditional operator (#112074)
1 parent ac5ae4c commit 8233e6b

File tree

16 files changed

+21
-21
lines changed

16 files changed

+21
-21
lines changed

src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ internal void InitializeSourceInfo(bool fNeedFileInfo, Exception? exception)
177177

178178
public bool IsLastFrameFromForeignExceptionStackTrace(int i)
179179
{
180-
return (rgiLastFrameFromForeignExceptionStackTrace == null) ? false : rgiLastFrameFromForeignExceptionStackTrace[i];
180+
return rgiLastFrameFromForeignExceptionStackTrace != null && rgiLastFrameFromForeignExceptionStackTrace[i];
181181
}
182182

183183
public int GetNumberOfFrames() { return iFrameCount; }

src/libraries/System.Private.CoreLib/src/System/Collections/Hashtable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ protected virtual bool KeyEquals(object? item, object key)
798798

799799
if (_keycomparer != null)
800800
return _keycomparer.Equals(item, key);
801-
return item == null ? false : item.Equals(key);
801+
return item != null && item.Equals(key);
802802
}
803803

804804
// Returns a collection representing the keys of this hashtable. The order

src/libraries/System.Private.CoreLib/src/System/Convert.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,12 @@ internal static object DefaultToType(IConvertible value, Type targetType, IForma
314314
// Conversions to Boolean
315315
public static bool ToBoolean([NotNullWhen(true)] object? value)
316316
{
317-
return value == null ? false : ((IConvertible)value).ToBoolean(null);
317+
return value != null && ((IConvertible)value).ToBoolean(null);
318318
}
319319

320320
public static bool ToBoolean([NotNullWhen(true)] object? value, IFormatProvider? provider)
321321
{
322-
return value == null ? false : ((IConvertible)value).ToBoolean(provider);
322+
return value != null && ((IConvertible)value).ToBoolean(provider);
323323
}
324324

325325
public static bool ToBoolean(bool value)

src/libraries/System.Private.CoreLib/src/System/Delegate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public bool MoveNext()
193193
return d1 is null;
194194
}
195195

196-
return ReferenceEquals(d2, d1) ? true : d2.Equals((object?)d1);
196+
return ReferenceEquals(d2, d1) || d2.Equals(d1);
197197
}
198198

199199
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -206,7 +206,7 @@ public bool MoveNext()
206206
return d1 is not null;
207207
}
208208

209-
return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1);
209+
return !ReferenceEquals(d2, d1) && !d2.Equals(d1);
210210
}
211211
}
212212
}

src/libraries/System.Private.CoreLib/src/System/MulticastDelegate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected MulticastDelegate([DynamicallyAccessedMembers(DynamicallyAccessedMembe
3535
return d1 is null;
3636
}
3737

38-
return ReferenceEquals(d2, d1) ? true : d2.Equals((object?)d1);
38+
return ReferenceEquals(d2, d1) || d2.Equals(d1);
3939
}
4040

4141
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -50,7 +50,7 @@ protected MulticastDelegate([DynamicallyAccessedMembers(DynamicallyAccessedMembe
5050
return d1 is not null;
5151
}
5252

53-
return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1);
53+
return !ReferenceEquals(d2, d1) && !d2.Equals(d1);
5454
}
5555
}
5656
#pragma warning restore CS0660, CS0661

src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public override string ToString()
196196
return true;
197197
}
198198

199-
return (left is null) ? false : left.Equals(right);
199+
return left is not null && left.Equals(right);
200200
}
201201

202202
public static bool operator !=(Assembly? left, Assembly? right) => !(left == right);

src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected ConstructorInfo() { }
3737
return true;
3838
}
3939

40-
return (left is null) ? false : left.Equals(right);
40+
return left is not null && left.Equals(right);
4141
}
4242

4343
public static bool operator !=(ConstructorInfo? left, ConstructorInfo? right) => !(left == right);

src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public virtual void RemoveEventHandler(object? target, Delegate? handler)
9292
return true;
9393
}
9494

95-
return (left is null) ? false : left.Equals(right);
95+
return left is not null && left.Equals(right);
9696
}
9797

9898
public static bool operator !=(EventInfo? left, EventInfo? right) => !(left == right);

src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected FieldInfo() { }
5656
return true;
5757
}
5858

59-
return (left is null) ? false : left.Equals(right);
59+
return left is not null && left.Equals(right);
6060
}
6161

6262
public static bool operator !=(FieldInfo? left, FieldInfo? right) => !(left == right);

src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public virtual Module Module
5959
return true;
6060
}
6161

62-
return (left is null) ? false : left.Equals(right);
62+
return left is not null && left.Equals(right);
6363
}
6464

6565
public static bool operator !=(MemberInfo? left, MemberInfo? right) => !(left == right);

0 commit comments

Comments
 (0)