Class BlockConstraints

Resolves a block type's input constraints — MinInputs, MaxInputs, AllowableBlocks — directly from the block class, so the palette / add-block dialog can gate which blocks may feed a new one.

Inheritance
BlockConstraints
Namespace: MOSAIC.Components.Factory
Assembly: MOSAIC.dll
Syntax
public static class BlockConstraints
Remarks

The block classes are the single source of truth: these constraints are declared as virtual properties on each block, so we read them straight off the type instead of hand-duplicating them in a catalog (drift-free) or scraping the .cs source (which breaks in a build that ships without source).

The properties are instance members, so reading them needs an object — but we must NOT run the constructor (device blocks open hardware there). We allocate an uninitialised instance and invoke the getter. That is sound only because every override returns a literal (e.g. => 2, => ["ClockBlock"]) and never touches instance state; if a future getter throws, the guarded fallback returns the BaseBlock defaults. Reading a field can instead silently return its uninitialised value, so field-dependent constraint getters are not supported.

Results are cached per type.

Fields

Cache

Declaration
private static readonly ConcurrentDictionary<Type, BlockConstraints.Inputs> Cache
Field Value
Type Description
ConcurrentDictionary<Type, BlockConstraints.Inputs>

Defaults

The BaseBlock defaults, used when a type can't be reflected safely.

Declaration
private static readonly BlockConstraints.Inputs Defaults
Field Value
Type Description
BlockConstraints.Inputs

Methods

Accepts(Type, string)

Whether a block of type blockType accepts a block whose runtime class is candidateClassName as an input (honours AllowableBlocks).

Declaration
public static bool Accepts(Type blockType, string candidateClassName)
Parameters
Type Name Description
Type blockType
string candidateClassName
Returns
Type Description
bool

CanBeSource(Type)

True when the block needs no inputs and can originate a stream.

Declaration
public static bool CanBeSource(Type blockType)
Parameters
Type Name Description
Type blockType
Returns
Type Description
bool
Remarks

The test is on Min, not Max: originating a stream means being able to run with nothing attached, which is not the same as refusing input altogether. A block that optionally accepts one upstream — UDPClient, which is receive-only until you give it something to forward — is a legitimate source.

For(Type)

Input constraints for blockType (a BaseBlock subclass).

Declaration
public static BlockConstraints.Inputs For(Type blockType)
Parameters
Type Name Description
Type blockType
Returns
Type Description
BlockConstraints.Inputs

Reflect(Type)

Declaration
private static BlockConstraints.Inputs Reflect(Type t)
Parameters
Type Name Description
Type t
Returns
Type Description
BlockConstraints.Inputs

Search documentation

Start typing to search the documentation.