Skip to main content

Definition

Assembly: Microsoft.Extensions.Configuration.Abstractions.dll Namespace: Microsoft.Extensions.Configuration

Syntax

Microsoft.Extensions.Configuration.IConfiguration

Summary

This type is defined in Microsoft.Extensions.Configuration.Abstractions.

Remarks

See Microsoft documentation for more information about the rest of the API.

Methods

BindWithJsonNames Extension

Extension method from Microsoft.Extensions.Configuration.IConfigurationExtensions
Binds the configuration values to the specified instance using JSON property names for key mapping. This method respects JsonPropertyNameAttribute when determining configuration keys, allowing for JSON-style configuration binding with different property naming conventions.

Syntax

public static void BindWithJsonNames<T>(Microsoft.Extensions.Configuration.IConfiguration configuration, T instance)

Parameters

NameTypeDescription
configurationMicrosoft.Extensions.Configuration.IConfigurationThe configuration instance to bind from.
instanceTThe instance to bind the configuration values to.

Type Parameters

  • T - The type of the instance to bind the configuration values to.

Examples

public class MyConfig
{
    [JsonPropertyName("api_endpoint")]
    public string ApiEndpoint { get; set; }

    public int Port { get; set; }
}

var config = new MyConfig();
configuration.BindWithJsonNames(config);
// Looks for "api_endpoint" and "Port" in configuration

Remarks

This method supports automatic type conversion for common types including DateTime, DateTimeOffset, and all types supported by Type). If a property has a JsonPropertyNameAttribute, the attribute’s Name value is used as the configuration key; otherwise, the property name is used directly.