Interface ITypeShape
- Namespace
- PolyType
- 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.
IGenericCustomAttributeProvider AttributeProvider { get; }
Property Value
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 attributesSystem.Runtime.InteropServices.*- COM interop attributesSystem.Diagnostics.*- Diagnostic attributesSystem.Reflection.DefaultMemberAttribute- Default member metadataSystem.CLSCompliantAttribute- CLS compliance markerMicrosoft.FSharp.Core.*- F# compiler generated attributes- Attributes marked with unmet ConditionalAttribute annotations.
Users requiring complete attribute resolution can use the Type property to access standard reflection-based attribute APIs, though this will be slower.
Events
Gets all available event shapes for the given type.
IReadOnlyList<IEventShape> Events { get; }
Property Value
- IReadOnlyList<IEventShape>
An enumeration of all available method shapes.
IsContextual
Gets a value indicating whether this is a contextual view rather than the provider's ordinary representation of Type.
bool IsContextual { get; }
Property Value
Remarks
Contextual shapes describe views specific to a structural role, such as a union's BaseType or an F# union case's object representation. This value is fixed for the lifetime of the shape. A false value identifies the ordinary representation of a type for a given Provider; it does not imply that shape instances are interned or reference-equal.
For a fixed provider and builder configuration, a cache keyed by Type must only reuse or store results for non-contextual shapes. Contextual shapes must bypass those entries, including delayed results and cached exceptions, while their non-contextual child shapes can use the same cache. TypeCache and TypeGenerationContext enforce this rule. This does not prohibit caching contextual shapes with a key that distinguishes their representations.
The property describes the shape, not the result of an arbitrary operation on it. Consumers must separately account for configuration or state that changes a generated result.
Kind
Gets determines the TypeShapeKind that the current shape supports.
TypeShapeKind Kind { get; }
Property Value
Methods
Gets all available method shapes for the given type.
IReadOnlyList<IMethodShape> Methods { get; }
Property Value
- IReadOnlyList<IMethodShape>
An enumeration of all available method shapes.
Provider
Gets the provider used to generate this instance.
ITypeShapeProvider Provider { get; }
Property Value
Type
Gets the underlying Type that this instance represents.
Type Type { get; }
Property Value
Methods
Accept(TypeShapeVisitor, object?)
Accepts a TypeShapeVisitor for type graph traversal.
object? Accept(TypeShapeVisitor visitor, object? state = null)
Parameters
visitorTypeShapeVisitorThe visitor to accept.
stateobjectThe state parameter to pass to the underlying visitor.
Returns
GetAssociatedTypeShape(Type)
Gets the shape for a type associated to this property's declared Type, as captured in AssociatedTypes or AssociatedTypes.
ITypeShape? GetAssociatedTypeShape(Type associatedType)
Parameters
associatedTypeTypeThe 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
- ITypeShape
The shape for the associated type, or null if no shape for the associated type is available.
Remarks
ReflectionTypeShapeProvider can produce the shape on demand without any AssociatedTypes, while SourceGenTypeShapeProvider is expected to only produce the shape 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
funcITypeShapeFuncThe generic function to be invoked.
stateobjectThe state to be passed to the function.
Returns
- object
The result produced by the function.