Skip to content

Commit 03576a1

Browse files
committed
Wrap any ?? throw news that go beyond 120 characters
1 parent cd92f58 commit 03576a1

File tree

16 files changed

+93
-64
lines changed

16 files changed

+93
-64
lines changed

src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public static unsafe void LoadInMemoryAssemblyInContext(IntPtr moduleHandle, Int
6969
[RequiresUnreferencedCode("C++/CLI is not trim-compatible", Url = "https://aka.ms/dotnet-illink/nativehost")]
7070
private static void LoadInMemoryAssemblyInContextImpl(IntPtr moduleHandle, IntPtr assemblyPath, AssemblyLoadContext? alc = null)
7171
{
72-
string assemblyPathString = Marshal.PtrToStringUni(assemblyPath) ?? throw new ArgumentOutOfRangeException(nameof(assemblyPath));
72+
string assemblyPathString = Marshal.PtrToStringUni(assemblyPath) ??
73+
throw new ArgumentOutOfRangeException(nameof(assemblyPath));
7374

7475
// We don't cache the ALCs or resolvers here since each IJW assembly will call this method at most once
7576
// (the load process rewrites the stubs that call here to call the actual methods they're supposed to)

src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ protected Delegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Al
8585
return invoke.Invoke(this, BindingFlags.Default, null, args, null);
8686
}
8787

88-
8988
public override bool Equals([NotNullWhen(true)] object? obj)
9089
{
9190
if (obj == null || !InternalEqualTypes(this, obj))
@@ -107,9 +106,11 @@ public override bool Equals([NotNullWhen(true)] object? obj)
107106
{
108107
if (d._methodPtrAux != IntPtr.Zero)
109108
return false; // different delegate kind
109+
110110
// they are both closed over the first arg
111111
if (_target != d._target)
112112
return false;
113+
113114
// fall through method handle check
114115
}
115116
else
@@ -121,19 +122,20 @@ public override bool Equals([NotNullWhen(true)] object? obj)
121122
/*
122123
if (_methodPtr != d._methodPtr)
123124
return false;
124-
*/
125+
*/
125126

126127
if (_methodPtrAux == d._methodPtrAux)
127128
return true;
129+
128130
// fall through method handle check
129131
}
130132

131133
// method ptrs don't match, go down long path
132-
//
133-
if (_methodBase == null || d._methodBase == null || _methodBase is not MethodInfo || d._methodBase is not MethodInfo)
134-
return InternalEqualMethodHandles(this, d);
135-
else
134+
135+
if (_methodBase is MethodInfo && d._methodBase is MethodInfo)
136136
return _methodBase.Equals(d._methodBase);
137+
else
138+
return InternalEqualMethodHandles(this, d);
137139
}
138140

139141
public override int GetHashCode()

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,24 @@ public override void Emit(OpCode opcode, MethodInfo meth)
6161
DynamicMethod? dynMeth = meth as DynamicMethod;
6262
if (dynMeth == null)
6363
{
64-
RuntimeMethodInfo rtMeth = meth as RuntimeMethodInfo ?? throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(meth));
64+
RuntimeMethodInfo rtMeth = meth as RuntimeMethodInfo ??
65+
throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(meth));
66+
6567
RuntimeType declaringType = rtMeth.GetRuntimeType();
66-
if (declaringType != null && (declaringType.IsGenericType || declaringType.IsArray))
67-
token = GetTokenFor(rtMeth, declaringType);
68-
else
69-
token = GetTokenFor(rtMeth);
68+
token = declaringType != null && (declaringType.IsGenericType || declaringType.IsArray) ?
69+
GetTokenFor(rtMeth, declaringType) :
70+
GetTokenFor(rtMeth);
7071
}
7172
else
7273
{
7374
// rule out not allowed operations on DynamicMethods
74-
if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn))
75+
if (opcode.Equals(OpCodes.Ldtoken) ||
76+
opcode.Equals(OpCodes.Ldftn) ||
77+
opcode.Equals(OpCodes.Ldvirtftn))
7578
{
7679
throw new ArgumentException(SR.Argument_InvalidOpCodeOnDynamicMethod);
7780
}
81+
7882
token = GetTokenFor(dynMeth);
7983
}
8084

@@ -106,15 +110,13 @@ public override void Emit(OpCode opcode, ConstructorInfo con)
106110
{
107111
ArgumentNullException.ThrowIfNull(con);
108112

109-
RuntimeConstructorInfo rtConstructor = con as RuntimeConstructorInfo ?? throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(con));
110-
RuntimeType declaringType = rtConstructor.GetRuntimeType();
111-
int token;
113+
RuntimeConstructorInfo rtConstructor = con as RuntimeConstructorInfo ??
114+
throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(con));
112115

113-
if (declaringType != null && (declaringType.IsGenericType || declaringType.IsArray))
114-
// need to sort out the stack size story
115-
token = GetTokenFor(rtConstructor, declaringType);
116-
else
117-
token = GetTokenFor(rtConstructor);
116+
RuntimeType declaringType = rtConstructor.GetRuntimeType();
117+
int token = declaringType != null && (declaringType.IsGenericType || declaringType.IsArray) ?
118+
GetTokenFor(rtConstructor, declaringType) : // need to sort out the stack size story
119+
GetTokenFor(rtConstructor);
118120

119121
EnsureCapacity(7);
120122
InternalEmit(opcode);
@@ -139,12 +141,12 @@ public override void Emit(OpCode opcode, FieldInfo field)
139141
{
140142
ArgumentNullException.ThrowIfNull(field);
141143

142-
RuntimeFieldInfo runtimeField = field as RuntimeFieldInfo ?? throw new ArgumentException(SR.Argument_MustBeRuntimeFieldInfo, nameof(field));
143-
int token;
144-
if (field.DeclaringType == null)
145-
token = GetTokenFor(runtimeField);
146-
else
147-
token = GetTokenFor(runtimeField, runtimeField.GetRuntimeType());
144+
RuntimeFieldInfo runtimeField = field as RuntimeFieldInfo ??
145+
throw new ArgumentException(SR.Argument_MustBeRuntimeFieldInfo, nameof(field));
146+
147+
int token = field.DeclaringType == null ?
148+
GetTokenFor(runtimeField) :
149+
GetTokenFor(runtimeField, runtimeField.GetRuntimeType());
148150

149151
EnsureCapacity(7);
150152
InternalEmit(opcode);

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ public override int GetMethodMetadataToken(ConstructorInfo constructor)
252252
{
253253
// some user derived ConstructorInfo
254254
// go through the slower code path, i.e. retrieve parameters and form signature helper.
255-
ParameterInfo[] parameters = constructor.GetParameters() ?? throw new ArgumentException(SR.Argument_InvalidConstructorInfo);
255+
ParameterInfo[] parameters = constructor.GetParameters() ??
256+
throw new ArgumentException(SR.Argument_InvalidConstructorInfo);
257+
256258
Type[] parameterTypes = new Type[parameters.Length];
257259
Type[][] requiredCustomModifiers = new Type[parameters.Length][];
258260
Type[][] optionalCustomModifiers = new Type[parameters.Length][];
@@ -990,7 +992,9 @@ private int GetMethodTokenNoLock(MethodInfo method, bool getGenericTypeDefinitio
990992
}
991993
else
992994
{
993-
Type declaringType = method.DeclaringType ?? throw new InvalidOperationException(SR.InvalidOperation_CannotImportGlobalFromDifferentModule);
995+
Type declaringType = method.DeclaringType ??
996+
throw new InvalidOperationException(SR.InvalidOperation_CannotImportGlobalFromDifferentModule);
997+
994998
if (declaringType.IsArray)
995999
{
9961000
// use reflection to build signature to work around the E_T_VAR problem in EEClass

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ private void AddOneArgTypeHelper(Type clsArgument, Type[]? requiredCustomModifie
276276
{
277277
for (int i = 0; i < optionalCustomModifiers.Length; i++)
278278
{
279-
Type t = optionalCustomModifiers[i] ?? throw new ArgumentNullException(nameof(optionalCustomModifiers));
279+
Type t = optionalCustomModifiers[i] ??
280+
throw new ArgumentNullException(nameof(optionalCustomModifiers));
281+
280282
if (t.HasElementType)
281283
throw new ArgumentException(SR.Argument_ArraysInvalid, nameof(optionalCustomModifiers));
282284

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,14 @@ private Delegate CreateDelegateInternal(Type delegateType, object? firstArgument
380380
{
381381
ArgumentNullException.ThrowIfNull(delegateType);
382382

383-
RuntimeType rtType = delegateType as RuntimeType ?? throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(delegateType));
383+
RuntimeType rtType = delegateType as RuntimeType ??
384+
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(delegateType));
385+
384386
if (!rtType.IsDelegate())
385387
throw new ArgumentException(SR.Arg_MustBeDelegate, nameof(delegateType));
386388

387-
Delegate d = Delegate.CreateDelegateInternal(rtType, this, firstArgument, bindingFlags) ?? throw new ArgumentException(SR.Arg_DlgtTargMeth);
388-
return d;
389+
return Delegate.CreateDelegateInternal(rtType, this, firstArgument, bindingFlags) ??
390+
throw new ArgumentException(SR.Arg_DlgtTargMeth);
389391
}
390392

391393
#endregion

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ internal sealed partial class RuntimeModule : Module
3333
RuntimeTypeHandle[] typeHandleArgs = new RuntimeTypeHandle[size];
3434
for (int i = 0; i < size; i++)
3535
{
36-
Type typeArg = genericArguments[i] ?? throw new ArgumentException(SR.Argument_InvalidGenericInstArray);
37-
typeArg = typeArg.UnderlyingSystemType;
38-
if (typeArg == null)
39-
throw new ArgumentException(SR.Argument_InvalidGenericInstArray);
36+
Type? typeArg = genericArguments[i]?.UnderlyingSystemType;
37+
4038
if (typeArg is not System.RuntimeType)
4139
throw new ArgumentException(SR.Argument_InvalidGenericInstArray);
40+
4241
typeHandleArgs[i] = typeArg.TypeHandle;
4342
}
4443
return typeHandleArgs;

src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ private static unsafe ref byte GetSpanDataFrom(
167167
[RequiresUnreferencedCode("Trimmer can't guarantee existence of class constructor")]
168168
public static void RunClassConstructor(RuntimeTypeHandle type)
169169
{
170-
RuntimeType rt = type.GetRuntimeType() ?? throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(type));
170+
RuntimeType rt = type.GetRuntimeType() ??
171+
throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(type));
172+
171173
RunClassConstructor(new QCallTypeHandle(ref rt));
172174
}
173175

@@ -184,7 +186,9 @@ public static void RunClassConstructor(RuntimeTypeHandle type)
184186

185187
public static void RunModuleConstructor(ModuleHandle module)
186188
{
187-
RuntimeModule rm = module.GetRuntimeModule() ?? throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(module));
189+
RuntimeModule rm = module.GetRuntimeModule() ??
190+
throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(module));
191+
188192
RunModuleConstructor(new QCallModule(ref rm));
189193
}
190194

@@ -198,7 +202,8 @@ public static void RunModuleConstructor(ModuleHandle module)
198202

199203
public static unsafe void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[]? instantiation)
200204
{
201-
IRuntimeMethodInfo methodInfo = method.GetMethodInfo() ?? throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(method));
205+
IRuntimeMethodInfo methodInfo = method.GetMethodInfo() ??
206+
throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(method));
202207

203208
// defensive copy of user-provided array, per CopyRuntimeTypeHandles contract
204209
instantiation = (RuntimeTypeHandle[]?)instantiation?.Clone();

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public static IntPtr OffsetOf(Type t, string fieldName)
3737
{
3838
ArgumentNullException.ThrowIfNull(t);
3939

40-
FieldInfo f = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new ArgumentException(SR.Format(SR.Argument_OffsetOfFieldNotFound, t.FullName), nameof(fieldName));
40+
FieldInfo f = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ??
41+
throw new ArgumentException(SR.Format(SR.Argument_OffsetOfFieldNotFound, t.FullName), nameof(fieldName));
42+
4143
if (f is not RtFieldInfo rtField)
4244
{
4345
throw new ArgumentException(SR.Argument_MustBeRuntimeFieldInfo, nameof(fieldName));

src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,9 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
27302730

27312731
ArgumentNullException.ThrowIfNull(interfaceType);
27322732

2733-
RuntimeType ifaceRtType = interfaceType as RuntimeType ?? throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(interfaceType));
2733+
RuntimeType ifaceRtType = interfaceType as RuntimeType ??
2734+
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(interfaceType));
2735+
27342736
RuntimeTypeHandle ifaceRtTypeHandle = ifaceRtType.TypeHandle;
27352737

27362738
TypeHandle.VerifyInterfaceIsImplemented(ifaceRtTypeHandle);

0 commit comments

Comments
 (0)