Table of Contents

Interface ITypeShape

Namespace
PolyType.Abstractions
Assembly
PolyType.dll

Provides a strongly typed shape model for a given .NET type.

public interface ITypeShape

Properties

AttributeProvider

Gets the provider used for type-level attribute resolution.

ICustomAttributeProvider? AttributeProvider { get; }

Property Value

ICustomAttributeProvider

Kind

Gets determines the TypeShapeKind that the current shape supports.

TypeShapeKind Kind { get; }

Property Value

TypeShapeKind

Provider

Gets the provider used to generate this instance.

ITypeShapeProvider Provider { get; }

Property Value

ITypeShapeProvider

Type

Gets the underlying Type that this instance represents.

Type Type { get; }

Property Value

Type

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.

GetAssociatedTypeFactory(Type)

Gets the factory for a type associated to this property's declared Type, as captured in AssociatedTypes or AssociatedTypes.

Func<object>? GetAssociatedTypeFactory(Type associatedType)

Parameters

associatedType Type

The associated type (which must be one found in the AssociatedTypes property). If the associated type is a generic type definition, the type arguments used on this shape's Type will be used to close the associated generic type.

Returns

Func<object>

A factory for the associated type, or null if no factory for the associated type is available.

Remarks

ReflectionTypeShapeProvider can produce the factory on demand without any AssociatedTypes, while SourceGenTypeShapeProvider is expected to only produce the factory that was explicitly requested via attribute.

Exceptions

InvalidOperationException

Thrown when this method is called on an instance that does not represent a generic type.

Invoke(ITypeShapeFunc, object?)

Invokes the specified generic function with the given state.

object? Invoke(ITypeShapeFunc func, object? state = null)

Parameters

func ITypeShapeFunc

The generic function to be invoked.

state object

The state to be passed to the function.

Returns

object

The result produced by the function.