Skip to content

Commit

Permalink
Don't check for null for structs (#4922)
Browse files Browse the repository at this point in the history
Fix to #4919
  • Loading branch information
JoshLove-msft authored Oct 30, 2024
1 parent 3f13f87 commit 6d168d3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private MethodProvider BuildImplicitToBinaryContent()
new MethodSignature(ClientModelPlugin.Instance.TypeFactory.RequestContentApi.RequestContentType.FrameworkType.Name, null, modifiers, null, null, [model]),
new MethodBodyStatement[]
{
new IfStatement(model.AsExpression.Equal(Null)) { Return(Null) },
!_isStruct ? new IfStatement(model.AsExpression.Equal(Null)) { Return(Null) } : MethodBodyStatement.Empty,
ClientModelPlugin.Instance.TypeFactory.RequestContentApi.ToExpression().Create(model)
},
this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,11 @@ public void TestBuildDeserializationMethodNestedSARD()
Assert.AreEqual(1, methodBodyString.Split(sardDeclaration).Length - 1);
}

[Test]
public void TestBuildImplicitToBinaryContent()
[TestCase(true)]
[TestCase(false)]
public void TestBuildImplicitToBinaryContent(bool useStruct)
{
var inputModel = InputFactory.Model("mockInputModel");
var inputModel = InputFactory.Model("mockInputModel", modelAsStruct: useStruct);
var (model, serialization) = CreateModelAndSerialization(inputModel);
var methods = serialization.Methods;

Expand All @@ -637,6 +638,7 @@ public void TestBuildImplicitToBinaryContent()

var methodBody = method?.BodyStatements;
Assert.IsNotNull(methodBody);
Assert.AreEqual(Helpers.GetExpectedFromFile(useStruct.ToString()), methodBody!.ToDisplayString());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if ((mockInputModel == null))
{
return null;
}
return global::System.ClientModel.BinaryContent.Create(mockInputModel, global::Sample.ModelSerializationExtensions.WireOptions);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return global::System.ClientModel.BinaryContent.Create(mockInputModel, global::Sample.ModelSerializationExtensions.WireOptions);

0 comments on commit 6d168d3

Please sign in to comment.