Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 488559e

Browse files
Merge pull request #418 from xamarin/the-return-of-throw-on-null
ThrowOnNull 2: the Wrath of Khan
2 parents a07890c + 64ba5e8 commit 488559e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

SwiftReflector/MarshalEngine.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,13 +1618,10 @@ CSBaseExpression MarshalNominal (CSParameter p)
16181618
CSLine ThrowOnNull (CSIdentifier parameterName)
16191619
{
16201620
// code to generate:
1621-
// if (p == null)
1622-
// throw new ArgumentNullException (nameof (p));
1623-
1624-
var ifTest = parameterName == CSConstant.Null;
1625-
var throwCall = CSThrow.ThrowLine (new ArgumentNullException (), CSFunctionCall.Nameof (parameterName));
1626-
var ifStatement = new CSIfElse (ifTest, CSCodeBlock.Create (throwCall), null);
1627-
return new CSLine (ifStatement, false);
1621+
// Exceptions.ThrowOnNull (parameterName, nameof (parameterName));
1622+
use.AddIfNotPresent (typeof (SwiftRuntimeLibrary.Exceptions));
1623+
var throwOnNull = CSFunctionCall.FunctionCallLine ("Exceptions.ThrowOnNull", parameterName, CSFunctionCall.Nameof (parameterName));
1624+
return throwOnNull;
16281625
}
16291626

16301627
CSBaseExpression MarshalClass (CSParameter p, NamedTypeSpec cl)

0 commit comments

Comments
 (0)