Table of Contents

Class TypeShapeExtensionAttribute

Namespace
PolyType
Assembly
PolyType.dll

An assembly-level attribute that can extend an existing type's generated shape, as if TypeShapeAttribute had been applied to the target type.

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class TypeShapeExtensionAttribute : Attribute
Inheritance
TypeShapeExtensionAttribute
Inherited Members

Remarks

While this attribute may be applied to an assembly multiple times, and may even be specified for a given target multiple times, the Marshaler property for a given target must either be null or must agree with other non-null properties on the attribute.

Constructors

TypeShapeExtensionAttribute(Type)

An assembly-level attribute that can extend an existing type's generated shape, as if TypeShapeAttribute had been applied to the target type.

public TypeShapeExtensionAttribute(Type target)

Parameters

target Type

The type to be extended.

Remarks

While this attribute may be applied to an assembly multiple times, and may even be specified for a given target multiple times, the Marshaler property for a given target must either be null or must agree with other non-null properties on the attribute.

Properties

AssociatedTypes

Types for which a shape should be generated when a type shape is generated for Target.

public Type[] AssociatedTypes { get; init; }

Property Value

Type[]

Remarks

If Target is a generic type definition, each type in this array must also be a generic type definition with the same number of generic type parameters.

IncludeMethods

Gets the binding flags that determine what method or event shapes should be included in the type shape.

public MethodShapeFlags IncludeMethods { get; init; }

Property Value

MethodShapeFlags

Remarks

This property controls how the Methods and Events collections will be populated. If left unspecified, only methods annotated with MethodShapeAttribute or EventShapeAttribute will be included.

This type can only be used to control inclusion of public methods in the shape models. Non-public methods can only be included individually via explicit attribute annotations.

InferClosedTypePolymorphism

Gets a value indicating whether compiler-provided closed-class metadata should be used to infer a polymorphic type hierarchy.

public bool InferClosedTypePolymorphism { get; init; }

Property Value

bool

The default value is false.

Remarks

When enabled, the annotated type must be a C# closed class and its shape is a union, including when the hierarchy contains no cases. Closed subclasses are expanded recursively; only terminal, non-closed subclasses are registered. Configuration on intermediate closed subclasses applies to their own shapes and does not affect inference for the annotated type.

Explicit DerivedTypeShapeAttribute registrations take precedence over KnownTypeAttribute registrations, which take precedence over inference. Inferred cases preserve compiler metadata order and receive implicit tags. Those tags are not stable across changes to the hierarchy.

This setting cannot be combined with a Marshaler or an explicitly requested Kind other than Union.

Kind

Gets the kind that should be generated for the annotated type.

public TypeShapeKind Kind { get; init; }

Property Value

TypeShapeKind

Remarks

Passing None will result in the generation of an IObjectTypeShape that does not contain any properties or constructors.

Exceptions

ArgumentOutOfRangeException

The specified value is not a valid TypeShapeKind.

Marshaler

Gets a type implementing an IMarshaler<TSource, TTarget> to a surrogate type.

public Type? Marshaler { get; init; }

Property Value

Type

Remarks

The type should have a parameterless constructor and must implement IMarshaler<TSource, TTarget> where either of the two generic types should match the annotated type.

Types that specify a Marshaler will be of shape ISurrogateTypeShape.

Requirements

Gets the elements of the generated shape that are required at runtime.

public TypeShapeRequirements Requirements { get; init; }

Property Value

TypeShapeRequirements

The default value is Full.

Remarks

This property only impacts generation of object shapes. All other shapes (e.g. collections, enums, unions) are always completely defined.

Target

Gets the target type.

public Type Target { get; }

Property Value

Type

Remarks

This is the type that is being extended. If the type is declared in the same assembly that contains this attribute, consider removing this attribute in favor of applying TypeShapeAttribute directly to the target type.