Skip to content

Add support for Guid Dictionary keys in IOptions binding. #116648

Open
@goldsam

Description

@goldsam

The current options binding implementation only supports the following Dictionary key types:

  • integers
  • strings
  • enums

Type keyType = dictionaryType.GenericTypeArguments[0];
Type valueType = dictionaryType.GenericTypeArguments[1];
bool keyTypeIsEnum = keyType.IsEnum;
bool keyTypeIsInteger =
keyType == typeof(sbyte) ||
keyType == typeof(byte) ||
keyType == typeof(short) ||
keyType == typeof(ushort) ||
keyType == typeof(int) ||
keyType == typeof(uint) ||
keyType == typeof(long) ||
keyType == typeof(ulong);
if (keyType != typeof(string) && !keyTypeIsEnum && !keyTypeIsInteger)
{
// We only support string, enum and integer (except nint-IntPtr and nuint-UIntPtr) keys
return null;
}

While #36540 would greatly enhance usability by adding extensibility for custom string->key conversions, adding direct support for Guid keys in in the interim would be enormously valuable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions