Skip to content
Merged
Prev Previous commit
Next Next commit
refine.
  • Loading branch information
haiyuazhang committed Sep 15, 2025
commit 7c86f33eeeb99f1d204ce0443eb04961dd8fbc23
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ private IEnumerable<MethodProvider> BuildMethodsForResource(ResourceClientProvid
collectionMethodSignature.ReturnDescription,
[.. collectionMethodSignature.Parameters, .. pathParameters],
collectionMethodSignature.Attributes);
var pathParameterArgs = pathParameters.Select(p => (ValueExpression)p).ToList();
var bodyStatement = Return(This.As<ArmResource>().GetCachedClient(new CodeWriterDeclaration("client"), client => New.Instance(collection.Type, [client, This.As<ArmResource>().Id(), .. pathParameterArgs])));

var bodyStatement = Return(This.As<ArmResource>().GetCachedClient(new CodeWriterDeclaration("client"), client => New.Instance(collection.Type, [client, This.As<ArmResource>().Id(), .. pathParameters])));
yield return new MethodProvider(
collectionMethodSignature,
bodyStatement,
Expand All @@ -242,16 +242,16 @@ private IEnumerable<MethodProvider> BuildMethodsForResource(ResourceClientProvid
if (getAsyncMethod is not null)
{
// we should be sure that this would never be null, but this null check here is just ensuring that we never crash
yield return BuildGetMethod(this, getAsyncMethod, collectionMethodSignature, pathParameters.ToList(), $"Get{resource.ResourceName}Async");
yield return BuildGetMethod(this, getAsyncMethod, collectionMethodSignature, pathParameters, $"Get{resource.ResourceName}Async");
}

if (getMethod is not null)
{
// we should be sure that this would never be null, but this null check here is just ensuring that we never crash
yield return BuildGetMethod(this, getMethod, collectionMethodSignature, pathParameters.ToList(), $"Get{resource.ResourceName}");
yield return BuildGetMethod(this, getMethod, collectionMethodSignature, pathParameters, $"Get{resource.ResourceName}");
}

static MethodProvider BuildGetMethod(TypeProvider enclosingType, MethodProvider resourceGetMethod, MethodSignature collectionGetSignature, List<ParameterProvider> pathParameters, string methodName)
static MethodProvider BuildGetMethod(TypeProvider enclosingType, MethodProvider resourceGetMethod, MethodSignature collectionGetSignature, IReadOnlyList<ParameterProvider> pathParameters, string methodName)
{
var signature = new MethodSignature(
methodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static IReadOnlyList<ValueExpression> PopulateArguments(
{
arguments.Add(Convert(contextualParameter.BuildValueExpression(idProperty), typeof(string), parameter.Type));
}
//Find matching parameter from pathFieldsParameters if enclosing type is ResourceCollectionClientProvider
else if (enclosingType is ResourceCollectionClientProvider collectionProvider && collectionProvider.TryGetPrivateFieldParameter(parameter, out var matchingField) && matchingField != null)
{
arguments.Add(matchingField);
}
else if (parameter.Type.Equals(typeof(RequestContent)))
{
// find the body parameter
Expand All @@ -52,22 +57,11 @@ public static IReadOnlyList<ValueExpression> PopulateArguments(
{
arguments.Add(requestContext);
}
else if (methodParameters.Any(p => p.WireInfo.SerializedName == parameter.WireInfo.SerializedName))
else
{
var methodParam = methodParameters.Single(p => p.WireInfo.SerializedName == parameter.WireInfo.SerializedName);
arguments.Add(Convert(methodParam, methodParam.Type, parameter.Type));
}
else
{
// Find matching parameter from pathFieldsParameters if enclosing type is ResourceCollectionClientProvider
if (enclosingType is ResourceCollectionClientProvider collectionProvider)
{
if (collectionProvider.TryGetPrivateFieldParameter(parameter, out var matchingField) && matchingField != null)
{
arguments.Add(matchingField);
}
}
}
}

return arguments;
Expand Down