Table of Contents

Interface IParameterShape

Namespace
PolyType.Abstractions
Assembly
PolyType.dll

Provides a strongly typed shape model for a given .NET method parameter, representing either an actual parameter or a member initializer.

public interface IParameterShape

Properties

AttributeProvider

Gets the provider used for parameter-level attribute resolution.

IGenericCustomAttributeProvider AttributeProvider { get; }

Property Value

IGenericCustomAttributeProvider

Remarks

Provides fast attribute resolution when using the source generator, otherwise this is wrapping standard reflection-based attribute resolution.

When using the source generator, the following categories of attributes are excluded to reduce trimmed application size:

  • System.Runtime.CompilerServices.* - Compiler-generated attributes
  • System.Runtime.InteropServices.* - COM interop attributes
  • System.Diagnostics.* - Diagnostic attributes
  • System.Reflection.DefaultMemberAttribute - Default member metadata
  • System.CLSCompliantAttribute - CLS compliance marker
  • Microsoft.FSharp.Core.* - F# compiler generated attributes
  • Attributes marked with unmet ConditionalAttribute annotations
Users requiring complete attribute resolution can use the ParameterInfo or MemberInfo properties to access standard reflection-based attribute APIs, though this will be slower.

DefaultValue

Gets the default value specified by the parameter, if applicable.

object? DefaultValue { get; }

Property Value

object

HasDefaultValue

Gets a value indicating whether the parameter has a default value.

bool HasDefaultValue { get; }

Property Value

bool

IsNonNullable

Gets a value indicating whether the parameter requires non-null values.

bool IsNonNullable { get; }

Property Value

bool

Remarks

Returns true if the parameter type is a non-nullable struct, a non-nullable reference type or the parameter has been annotated with the DisallowNullAttribute.

Conversely, it could return false if a non-nullable parameter has been annotated with AllowNullAttribute.

IsPublic

Gets a value indicating whether the parameter is a public property or field initializer.

bool IsPublic { get; }

Property Value

bool

IsRequired

Gets a value indicating whether a value is required for the current parameter.

bool IsRequired { get; }

Property Value

bool

Remarks

A parameter is reported as required if it is either a parameter without a default value or related to a property declared with the required modifier where the constructor is not annotated with SetsRequiredMembersAttribute. This value will switch to the value set by IsRequired or IsRequired (successively) if they are set.

Kind

Gets specifies the kind of the current parameter.

ParameterKind Kind { get; }

Property Value

ParameterKind

MemberInfo

Gets the underlying MemberInfo representing the parameter, if available.

MemberInfo? MemberInfo { get; }

Property Value

MemberInfo

Remarks

Returns a PropertyInfo or FieldInfo when the parameter kind is MemberInitializer, or null otherwise.

Name

Gets the name of the method parameter.

string Name { get; }

Property Value

string

ParameterInfo

Gets the underlying ParameterInfo representing the parameter, if available.

ParameterInfo? ParameterInfo { get; }

Property Value

ParameterInfo

Remarks

Returns a value when the parameter kind is MethodParameter, or null otherwise.

ParameterType

Gets the shape of the method parameter type.

ITypeShape ParameterType { get; }

Property Value

ITypeShape

Position

Gets the 0-indexed position of the current method parameter.

int Position { get; }

Property Value

int

Methods

Accept(TypeShapeVisitor, object?)

Accepts an TypeShapeVisitor for strongly-typed traversal.

object? Accept(TypeShapeVisitor visitor, object? state = null)

Parameters

visitor TypeShapeVisitor

The visitor to accept.

state object

The state parameter to pass to the underlying visitor.

Returns

object

The object result returned by the visitor.