Skip to content

Allow Property Replacement in Generated ClientSettings Using Custom Code #10902

@jorgerangel-msft

Description

@jorgerangel-msft

Consider this scenario where the generated Url setting property should be replaced with the one defined in custom code.

// CUSTOM
public partial class QueueClientSettings
{
    /// <summary> Gets or sets the Queue Uri. </summary>
    [CodeGenMember("Url")]
    public Uri QueueUri { get; set; }
}

This leads to code that doesn't compile instead:

// GENERATED
/// <summary> Represents the settings used to configure a <see cref="QueueClient"/> that can be loaded from an <see cref="IConfigurationSection"/>. </summary>
[Experimental("SCME0002")]
public partial class QueueClientSettings : ClientSettings
{
    /// <summary> Gets or sets the Options. </summary>
    public QueueClientOptions Options { get; set; }

    /// <summary> Binds configuration values from the given section. </summary>
    /// <param name="section"> The configuration section. </param>
    protected override void BindCore(IConfigurationSection section)
    {
        if (Uri.TryCreate(section["Url"], UriKind.Absolute, out Uri url))
        {
            this.Url = url;
        }
        string connectionString = section["ConnectionString"];
        if (!string.IsNullOrEmpty(connectionString))
        {
            ConnectionString = connectionString;
        }
        string queueName = section["QueueName"];
        if (!string.IsNullOrEmpty(queueName))
        {
            QueueName = queueName;
        }
        IConfigurationSection optionsSection = section.GetSection("Options");
        if (optionsSection.Exists())
        {
            Options = new QueueClientOptions(optionsSection);
        }
    }
}

We should honor any custom code replacements done in ClientSettings

Metadata

Metadata

Labels

bugSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions