Repository: Azure/azure-sdk-for-net
File: sdk/provisioning/Generator/src/Model/Specification.Analyze.cs (C#)

Code before:
                                    resource.HiddenResourceVersions.Add(v);
                                }
                            }
                        }
                    }
                }
            });
    }

    /// <summary>
    /// Find the api-version used by the mgmt library for a given resource
    /// by looking at the RestOperations classes referenced by its ArmResource type.
    /// </summary>
    private static string? FindMgmtApiVersion(Resource resource)
    {
        Type armType = resource.ArmType!;

        // Look at the ArmResource type's fields to find RestOperations types
        foreach (FieldInfo field in armType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
        {
            Type fieldType = field.FieldType;
            if (!fieldType.Name.EndsWith("RestOperations")) { continue; }

            string? version = ExtractApiVersionFromRestOperations(fieldType);
            if (version is not null) { return version; }
        }

        return null;
    }

    /// <summary>
    /// Extract the default api-version string from a RestOperations constructor
    /// by parsing its IL for string literals matching the api-version pattern.
    /// </summary>
    private static string? ExtractApiVersionFromRestOperations(Type restOperationsType)
    {
        ConstructorInfo? constructor = restOperationsType
            .GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
            .FirstOrDefault();
        if (constructor is null) { return null; }

        MethodBody? body = constructor.GetMethodBody();
        if (body is null) { return null; }

        byte[] il = body.GetILAsByteArray()!;
        Module module = restOperationsType.Module;

        // Search for ldstr opcodes (0x72) and find api-version string literals
        for (int i = 0; i < il.Length - 4; i++)
        {
            if (il[i] != 0x72) { continue; } // OpCodes.Ldstr

Review comment (suggestion):
this part is not correct.
Indeed a resource arm type will have RestOperation private fields, which contains the api-version as a field.
But one resource might contain multiple RestOperation fields, but only one of them (we cannot just assume it is the first) is correct, which is the rest operation instance called in the Get method - or CreateOrUpdate method (this method is not on the resource, but on collection).
Please double confirm this.

Code after:
                    resource.DefaultResourceVersion = defaultVersion;

                    // Merge existing hidden versions with any added by Customize()
                    if (existingHiddenVersions.Count > 0)
                    {
                        if (resource.HiddenResourceVersions is null)
                        {
                            resource.HiddenResourceVersions = existingHiddenVersions;
                        }
                        else
                        {
                            foreach (string v in existingHiddenVersions)
                            {
                                if (!resource.HiddenResourceVersions.Contains(v))
                                {
                                    resource.HiddenResourceVersions.Add(v);
                                }
                            }
                        }
                    }
                }
            });
    }

    /// <summary>
    /// Extract the default api-version from a CreateOrUpdate method's XML doc comment.
    /// The generated mgmt libraries include a "Default Api Version" item in the
    /// method's summary XML doc list, e.g.:
    /// <code>
    ///   &lt;item&gt;
    ///     &lt;term&gt;Default Api Version&lt;/term&gt;
    ///     &lt;description&gt;2025-06-01&lt;/description&gt;
    ///   &lt;/item&gt;
    /// </code>
    /// </summary>
    private string? ExtractApiVersionFromXmlDoc(MethodInfo method)
    {
        // Use the Specification's existing DocComments reader which has
        // already loaded the XML doc file for the mgmt assembly
        string? summary = DocComments.GetSummary(method);
        if (summary is null) { return null; }

        // The summary text contains the flattened content including
        // "Default Api Version" followed by the version string.
        const string marker = "Default Api Version";
        int idx = summary.IndexOf(marker, StringComparison.OrdinalIgnoreCase);
        if (idx < 0) { return null; }

        // Extract the version after the marker - it follows after some whitespace/punctuation
        string rest = summary[(idx + marker.Length)..].Trim().TrimStart('.').Trim();