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
markupMarkupConfigurationThe markup configuration supplying built-in namespaces and short names.
assembliesIAssemblyResolverThe 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
nameXNameThe XML name to resolve.
nodeIXmlLineInfoThe node the name appears on, for error positions.
sourcePathstringThe 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
typeNamestringEither a prefix-qualified name (
local:PlayerViewModel), resolved throughscope's namespace declarations; an unprefixed name that resolves againstscope'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).scopeXElementThe element the attribute appears on, whose prefixes are in scope.
nodeIXmlLineInfoThe node the name appears on, for error positions.
sourcePathstringThe 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
nameXNameThe XML name to resolve.
typeTypeThe resolved type, when this returns true.
failurestringA message describing why resolution failed, when this returns false.