Table of Contents

Class GenerateShapeAttribute

Namespace
PolyType
Assembly
PolyType.dll

Instructs the PolyType source generator to include the annotated type in the ITypeShapeProvider that it generates.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
[Conditional("NEVER")]
public sealed class GenerateShapeAttribute : Attribute
Inheritance
GenerateShapeAttribute
Inherited Members

Remarks

For projects targeting .NET 8 or later, this additionally augments the type with an implementation of IShapeable for the type.

Projects targeting older versions of .NET need to access the generated ITypeShapeProvider instance through the static property added to classes annotated with the GenerateShapeForAttribute<T> or GenerateShapeForAttribute.

Properties

IncludeMethods

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

public MethodShapeFlags IncludeMethods { get; init; }

Property Value

MethodShapeFlags

Remarks

If left unspecified, only methods annotated with MethodShapeAttribute 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 MethodShapeAttribute annotations.

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.