Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address code review feedback - simplify ModelFactoryVisitor
Co-authored-by: live1206 <[email protected]>
  • Loading branch information
Copilot and live1206 committed Dec 11, 2025
commit 4d0cbc2ae7e4e660738b45987643c85cc8681a0f
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,19 @@ internal class ModelFactoryVisitor : ScmLibraryVisitor
{ "ETag", "etag" }
};

private ModelFactoryProvider? _modelFactory;
private bool _modelTypesEnsured = false;

protected override TypeProvider? VisitType(TypeProvider type)
{
if (type is ModelFactoryProvider modelFactory)
{
// Store the model factory for post-processing
_modelFactory = modelFactory;
}
return base.VisitType(type);
}

protected override TypeProvider? PostVisitType(TypeProvider type)
{
// Process model factory after all models have been visited
if (type is ModelFactoryProvider && _modelFactory != null && !_modelTypesEnsured)
if (type is ModelFactoryProvider modelFactory && !_modelTypesEnsured)
{
// Ensure model types are built now that all flattening is complete
ManagementClientGenerator.Instance.OutputLibrary.EnsureModelTypesBuilt();
_modelTypesEnsured = true;

var updatedMethods = new List<MethodProvider>();
foreach (var method in _modelFactory.Methods)
foreach (var method in modelFactory.Methods)
{
var returnType = method.Signature.ReturnType;
if (returnType is not null && ManagementClientGenerator.Instance.OutputLibrary.IsModelFactoryModelType(returnType))
Expand All @@ -56,7 +45,7 @@ internal class ModelFactoryVisitor : ScmLibraryVisitor
updatedMethods.Add(method);
}
}
_modelFactory.Update(methods: updatedMethods);
modelFactory.Update(methods: updatedMethods);
}

return base.PostVisitType(type);
Expand Down
Loading