Interface IMarkupBuilder
- Namespace
- Icy.Markup
- Assembly
- IcyUI.dll
Builds objects from markup fragments, or applies single attributes, exactly as MarkupLoader would while loading a whole document.
public interface IMarkupBuilder
- Extension Methods
Remarks
This is the seam design tooling uses to mirror a markup edit onto an already loaded tree, reusing the loader's
type resolution, value conversion, markup extensions and name scopes instead of duplicating them.
MarkupLoader implements it: IMarkupBuilder builder = new MarkupLoader(configuration);.
Everything built through a MarkupLoadScope is reported to that scope's observer with ObjectCreated(MarkupLoadScope, XElement, object) and MemberApplied(MarkupLoadScope, XObject, object, MarkupMember, object?, IBinding?), as during the original load.
Methods
ApplyAttribute(MarkupLoadScope, object, XAttribute)
Applies one attribute to an already built object, exactly as the loader would.
void ApplyAttribute(MarkupLoadScope scope, object target, XAttribute attribute)
Parameters
scopeMarkupLoadScopeThe scope of the document
targetbelongs to.targetobjectThe object to apply the attribute to.
attributeXAttributeThe attribute. It must belong to an element (one from ParseFragment(string, IReadOnlyDictionary<string, string>)), so its namespace and any directive resolve.
Exceptions
- MarkupException
The attribute or its value breaks a rule of the language.
- ArgumentException
attributedoesn't belong to an element.- InvalidOperationException
The scope's tree has already been collected.
BuildFragment(MarkupLoadScope, XElement, UIElement?)
Builds a fragment's object tree in the context of an observed document.
object BuildFragment(MarkupLoadScope scope, XElement fragment, UIElement? liveParent)
Parameters
scopeMarkupLoadScopeThe scope of the document the fragment belongs to.
fragmentXElementThe fragment, as returned by ParseFragment(string, IReadOnlyDictionary<string, string>).
liveParentUIElementThe live element the result will be added to, or null.
{StaticResource}resolves through it and its ancestors, as it would through the elements under construction during a load. The result isn't added to it; that's the caller's job.
Returns
- object
The built object.
x:Names inside it are registered in the scope's name scope.
Exceptions
- MarkupException
The fragment breaks a rule of the language.
- InvalidOperationException
The scope's tree has already been collected.
ParseFragment(string, IReadOnlyDictionary<string, string>)
Parses a markup fragment with the same reader settings the loader uses for documents.
XElement ParseFragment(string text, IReadOnlyDictionary<string, string> namespaces)
Parameters
textstringThe fragment: exactly one element, with any content.
namespacesIReadOnlyDictionary<string, string>The namespace declarations the fragment inherits from where it sits in its document, keyed by prefix (the empty string for the default namespace). The
xprefix is always predeclared.
Returns
- XElement
The fragment's element, with line information relative to
text.
Exceptions
- MarkupException
The fragment isn't well-formed XML, or uses an undeclared prefix.