Table of Contents

Class MultiProviderTypeCache

Namespace
PolyType.Utilities
Assembly
PolyType.dll

Stores weakly referenced TypeCache instances keyed to a particular ITypeShapeProvider instance.

public sealed class MultiProviderTypeCache
Inheritance
MultiProviderTypeCache
Inherited Members

Constructors

MultiProviderTypeCache()

Initializes a new instance of the MultiProviderTypeCache class.

public MultiProviderTypeCache()

Properties

CacheExceptions

Gets a value indicating whether exceptions should be cached.

public bool CacheExceptions { get; init; }

Property Value

bool

DelayedValueFactory

Gets a factory method governing delayed value initialization in case of recursive types.

public IDelayedValueFactory? DelayedValueFactory { get; init; }

Property Value

IDelayedValueFactory

ValueBuilderFactory

Gets a factory method governing the creation of values when invoking the GetOrAdd(ITypeShape) method.

public Func<TypeGenerationContext, ITypeShapeFunc>? ValueBuilderFactory { get; init; }

Property Value

Func<TypeGenerationContext, ITypeShapeFunc>

Remarks

This factory takes a newly created TypeGenerationContext to construct an ITypeShapeFunc that is responsible for generating the value associated with a given type shape. The generation context wraps the created ITypeShapeFunc and can be used to recursively look up and cache values for nested types, including handling potentially cyclic type graphs.

Because the generation context implements ITypeShapeFunc, this factory can effectively be seen as a Func<ITypeShapeFunc, ITypeShapeFunc> where the resultant function is being passed a reference to itself for the purpose of handling recursive calls. This makes it a specialized form of the Y-combinator.

Methods

GetOrAdd(ITypeShape)

Gets or adds a value keyed on the type represented by typeShape and its ITypeShapeProvider.

public object? GetOrAdd(ITypeShape typeShape)

Parameters

typeShape ITypeShape

The type shape representing the key type.

Returns

object

The final computed value.

GetOrAdd(Type, ITypeShapeProvider)

Gets or adds a value keyed on the type represented by provider.

public object? GetOrAdd(Type type, ITypeShapeProvider provider)

Parameters

type Type

The type representing the key type.

provider ITypeShapeProvider

The type shape provider used to resolve the type shape.

Returns

object

The final computed value.

GetScopedCache(ITypeShape)

Gets or creates a cache scoped to the specified typeShape and its ITypeShapeProvider.

public TypeCache GetScopedCache(ITypeShape typeShape)

Parameters

typeShape ITypeShape

The shape provider key.

Returns

TypeCache

A TypeCache scoped to typeShape.