Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source generation should formally format the type it wraps #350

Open
SteveDunn opened this issue Jan 28, 2023 · 1 comment
Open

Source generation should formally format the type it wraps #350

SteveDunn opened this issue Jan 28, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@SteveDunn
Copy link
Owner

SteveDunn commented Jan 28, 2023

Describe the feature

This is a suggested improvement to the way the source is generated for the underlying type that is bing wrapped. There is no particular bug associated with this, but the suggested alternative looks a lot more robust in terms of including the namespace, any global alias if needed, and any escaping, if needed.

The current code, when setting the underlying type (VoWorkItem.cs), uses INamedTypeSymbol.FullName:

    public INamedTypeSymbol UnderlyingType
    {
        get => _underlyingType;
        set
        {
            _underlyingType = value;
            _underlyingTypeFullName = value.FullName() ?? value?.Name ?? throw new InvalidOperationException(
                "No underlying type specified - please file a bug at https://github.com/SteveDunn/Vogen/issues/new?assignees=&labels=bug&template=BUG_REPORT.yml");
        }

Instead of value.FullName, then falling back to value.Name, it should instead use

            _underlyingTypeFullName = value.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);

That is defined in Roslyn as:

        /// <summary>
        /// Formats the names of all types and namespaces in a fully qualified style (including the global alias).
        /// </summary>
        /// <remarks>
        /// The current behavior will not output the fully qualified style as expected for member symbols (such as properties) because memberOptions is not set.
        /// For example, MyNamespace.MyClass.MyPublicProperty will return as MyPublicProperty.
        /// The current behavior displayed here will be maintained for backwards compatibility.
        /// </remarks>
        public static SymbolDisplayFormat FullyQualifiedFormat { get; } =
            new SymbolDisplayFormat(
                globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
                typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
                genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
                miscellaneousOptions:
                    SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
                    SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
@SteveDunn SteveDunn added the enhancement New feature or request label Jan 28, 2023
@SteveDunn
Copy link
Owner Author

I found and fixed a bug in Roslyn that stops us from using this. Revisit in the future.

@SteveDunn SteveDunn self-assigned this Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant