Table of Contents

Class MarkupTypeResolver

Namespace
Icy.Markup
Assembly
IcyUI.dll

Resolves markup names - element tags, attached-property owners, and type-valued directives - to CLR types.

public sealed class MarkupTypeResolver
Inheritance
MarkupTypeResolver
Inherited Members
Extension Methods

Remarks

Two forms exist. A prefixed name is resolved through the XML namespace its prefix is bound to, which must be a clr-namespace namespace naming a CLR namespace and, optionally, an assembly. An unprefixed name is looked for among the built-in controls first, then among the short names registered on MarkupConfiguration.

Built-ins deliberately win over short names, and registering a short name over a built-in is rejected at registration time - see RegisterShortName(Type, string?).

Constructors

MarkupTypeResolver(MarkupConfiguration, IAssemblyResolver)

Resolves markup names - element tags, attached-property owners, and type-valued directives - to CLR types.

public MarkupTypeResolver(MarkupConfiguration markup, IAssemblyResolver assemblies)

Parameters

markup MarkupConfiguration

The markup configuration supplying built-in namespaces and short names.

assemblies IAssemblyResolver

The resolver used to find assemblies and fully-qualified types.

Remarks

Two forms exist. A prefixed name is resolved through the XML namespace its prefix is bound to, which must be a clr-namespace namespace naming a CLR namespace and, optionally, an assembly. An unprefixed name is looked for among the built-in controls first, then among the short names registered on MarkupConfiguration.

Built-ins deliberately win over short names, and registering a short name over a built-in is rejected at registration time - see RegisterShortName(Type, string?).

Methods

Resolve(XName, IXmlLineInfo?, string?)

Resolves an element or attached-property-owner name to a type.

public Type Resolve(XName name, IXmlLineInfo? node, string? sourcePath)

Parameters

name XName

The XML name to resolve.

node IXmlLineInfo

The node the name appears on, for error positions.

sourcePath string

The markup file's path, for error messages.

Returns

Type

The resolved type.

Exceptions

MarkupException

The name doesn't resolve to any type.

ResolveTypeName(string, XElement, IXmlLineInfo?, string?)

Resolves a type named in an attribute value, such as TargetType, x:Class, or x:DataType.

public Type ResolveTypeName(string typeName, XElement scope, IXmlLineInfo? node, string? sourcePath)

Parameters

typeName string

Either a prefix-qualified name (local:PlayerViewModel), resolved through scope's namespace declarations; an unprefixed name that resolves against scope's default namespace the same way an element tag would (Button, when the default namespace is built-in); or, failing that, a plain CLR name (MyGame.UI.PlayerViewModel), resolved through FindType(string).

scope XElement

The element the attribute appears on, whose prefixes are in scope.

node IXmlLineInfo

The node the name appears on, for error positions.

sourcePath string

The markup file's path, for error messages.

Returns

Type

The resolved type.

Remarks

The built-in/short-name attempt exists so TargetType="Button" resolves the same Button a <Button> tag would, instead of falling straight to FindType(string)'s unqualified, load-order-dependent scan of every type in every loaded assembly - which a short, common control name can resolve incorrectly once a host (a WinForms- backed game window, say) has loaded an unrelated same-named type first.

Exceptions

MarkupException

The name doesn't resolve to any type.

TryResolve(XName, out Type?, out string?)

Attempts to resolve an element or attached-property-owner name to a type.

public bool TryResolve(XName name, out Type? type, out string? failure)

Parameters

name XName

The XML name to resolve.

type Type

The resolved type, when this returns true.

failure string

A message describing why resolution failed, when this returns false.

Returns

bool

true when the name resolved.