Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private HashSet<CSharpType> ModelFactoryModels
{
get
{
BuildModelTypes();
EnsureModelTypesBuilt();
return _modelFactoryModels!;
}
}
Expand All @@ -225,12 +225,15 @@ private HashSet<CSharpType> AllModelTypes
{
get
{
BuildModelTypes();
EnsureModelTypesBuilt();
return _allModelTypes!;
}
}

private void BuildModelTypes()
/// <summary>
/// Ensures model types are built. This should be called after all model modifications (like flattening) are complete.
/// </summary>
internal void EnsureModelTypesBuilt()
{
if (_modelFactoryModels is not null && _allModelTypes is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ internal class ModelFactoryVisitor : ScmLibraryVisitor
{ "ETag", "etag" }
};

protected override TypeProvider? VisitType(TypeProvider type)
private bool _modelTypesEnsured = false;

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

var updatedMethods = new List<MethodProvider>();
foreach (var method in modelFactory.Methods)
{
Expand All @@ -39,9 +49,9 @@ internal class ModelFactoryVisitor : ScmLibraryVisitor
}
}
modelFactory.Update(methods: updatedMethods);
return modelFactory;
}
return base.VisitType(type);

return base.PostVisitType(type);
}

private void FixArgumentNullExceptionXmlDoc(MethodProvider method)
Expand Down