Table of Contents

Class DefaultMetadataResolver

Namespace
McMaster.Extensions.CommandLineUtils.SourceGeneration
Assembly
McMaster.Extensions.CommandLineUtils.dll

Default implementation that checks the registry first, falls back to reflection.

public sealed class DefaultMetadataResolver : IMetadataResolver
Inheritance
object
DefaultMetadataResolver
Implements

Fields

Instance

Gets the singleton instance of the default metadata resolver.

public static readonly DefaultMetadataResolver Instance

Field Value

DefaultMetadataResolver

Methods

GetProvider(Type)

Gets the metadata provider for a type. Returns generated metadata if available, otherwise uses reflection.

[RequiresUnreferencedCode("Falls back to reflection when no generated metadata is available. Use the source generator for AOT compatibility.")]
public ICommandMetadataProvider GetProvider(Type modelType)

Parameters

modelType Type

The model type.

Returns

ICommandMetadataProvider

A metadata provider for the type.

Remarks

This method first checks for source-generated metadata (AOT-friendly). If no generated metadata exists, it falls back to reflection-based metadata extraction. For full AOT compatibility, ensure the CommandLineUtils.Generators package is referenced and the source generator runs during compilation.

GetProvider<TModel>()

Gets the metadata provider for a type. Returns generated metadata if available, otherwise uses reflection.

[RequiresUnreferencedCode("Falls back to reflection when no generated metadata is available. Use the source generator for AOT compatibility.")]
public ICommandMetadataProvider<TModel> GetProvider<TModel>() where TModel : class

Returns

ICommandMetadataProvider<TModel>

A metadata provider for the type.

Type Parameters

TModel

The model type.

Remarks

This method first checks for source-generated metadata (AOT-friendly). If no generated metadata exists, it falls back to reflection-based metadata extraction. For full AOT compatibility, ensure the CommandLineUtils.Generators package is referenced and the source generator runs during compilation.

HasGeneratedMetadata(Type)

Checks if generated metadata is available for a type.

public bool HasGeneratedMetadata(Type modelType)

Parameters

modelType Type

The model type.

Returns

bool

True if generated metadata is available; otherwise, false.