Table of Contents

Class XFactory

Namespace
Hi.Common.XmlUtils
Assembly
HiGeom.dll

Factory for generating objects from XML elements using registered generator functions.

public class XFactory
Inheritance
XFactory
Inherited Members
Extension Methods

Remarks

Each XFactory instance owns its own Generators registry. A process-wide Default singleton serves the common case (single shared factory across the simulation pipeline); other instances can be created for test isolation or parallel pipelines that need disjoint registries.

Types that participate in XML round-trip expose a public static void Reg(XFactory factory = null) method that adds themselves (and chains Reg(factory) on dependents) to the given factory's Generators. Boot roots (e.g. LocalProjectService.Reg()) call the top-level Reg() once at startup with the default factory.

The static Gen<T> / GenByChild<T> / GenByFile<T> entry points always read from Default. Callers that need to deserialize from a custom factory's registry must look up the delegate via factory.Generators[xname] directly.

Properties

Default

Process-wide default factory used by the static Gen<T> family. Reg-style methods register here when called with no explicit factory argument.

public static XFactory Default { get; }

Property Value

XFactory

Generators

XML-name → generator-function map for this factory instance. Populated by each type's Reg(this) call.

public Dictionary<string, XFactory.XGeneratorDelegate> Generators { get; }

Property Value

Dictionary<string, XFactory.XGeneratorDelegate>

Methods

GenByChild<T>(XElement, string, IProgress<object>, bool, object[])

Generates an object of type T from the first child element (discards relative file path).

public static T GenByChild<T>(XElement src, string baseDirectory, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class

Parameters

src XElement
baseDirectory string
progress IProgress<object>
enableRebase bool
res object[]

Returns

T

Type Parameters

T

GenByChild<T>(XElement, string, out string, IProgress<object>, bool, object[])

Generates an object of type T from the first child element of the provided XML element.

public static T GenByChild<T>(XElement src, string baseDirectory, out string relFile, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class

Parameters

src XElement
baseDirectory string
relFile string
progress IProgress<object>
enableRebase bool
res object[]

Returns

T

Type Parameters

T

GenByFile<T>(string, string, IProgress<object>, bool, object[])

Generates an object of type T from an XML file.

public static T GenByFile<T>(string baseDirectory, string relFile, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class

Parameters

baseDirectory string
relFile string
progress IProgress<object>
enableRebase bool
res object[]

Returns

T

Type Parameters

T

GenFileRefSourceByChild<T>(XElement, string, IProgress<object>, bool, object[])

Generates a FileRefSource<T> from the first child element.

public static FileRefSource<T> GenFileRefSourceByChild<T>(XElement src, string baseDirectory, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class, IMakeXmlSource

Parameters

src XElement
baseDirectory string
progress IProgress<object>
enableRebase bool
res object[]

Returns

FileRefSource<T>

Type Parameters

T

GenFileRefSourceByFile<T>(string, string, IProgress<object>, bool, object[])

Generates a FileRefSource<T> from an XML file.

public static FileRefSource<T> GenFileRefSourceByFile<T>(string baseDirectory, string relFile, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class, IMakeXmlSource

Parameters

baseDirectory string
relFile string
progress IProgress<object>
enableRebase bool
res object[]

Returns

FileRefSource<T>

Type Parameters

T

GenFileRefSource<T>(XElement, string, IProgress<object>, bool, object[])

Generates a FileRefSource<T> from an XML element.

public static FileRefSource<T> GenFileRefSource<T>(XElement src, string baseDirectory, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class, IMakeXmlSource

Parameters

src XElement
baseDirectory string
progress IProgress<object>
enableRebase bool
res object[]

Returns

FileRefSource<T>

Type Parameters

T

GenListSkippingUnloadable<T>(IEnumerable<XElement>, string, IProgress<object>, bool, object[])

Deserializes each element of elements into a T, skipping — instead of throwing on — any element whose XName is not registered (e.g. a renamed or removed component) or whose generator throws. Each skipped element is reported to progress as a Warning. Use when a partially-loadable list (such as a saved pipeline whose schema has drifted while a feature is in development) is preferable to aborting the whole load.

public static List<T> GenListSkippingUnloadable<T>(IEnumerable<XElement> elements, string baseDirectory, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class

Parameters

elements IEnumerable<XElement>
baseDirectory string
progress IProgress<object>
enableRebase bool
res object[]

Returns

List<T>

Type Parameters

T

Gen<T>(XElement, string, IProgress<object>, bool, object[])

Generates an object of type T from an XML element (discards relative file path).

public static T Gen<T>(XElement src, string baseDirectory, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class

Parameters

src XElement
baseDirectory string
progress IProgress<object>
enableRebase bool
res object[]

Returns

T

Type Parameters

T

Gen<T>(XElement, string, out string, IProgress<object>, bool, object[])

Generates an object of type T from an XML element using Default.

public static T Gen<T>(XElement src, string baseDirectory, out string relFile, IProgress<object> progress, bool enableRebase = true, object[] res = null) where T : class

Parameters

src XElement
baseDirectory string
relFile string
progress IProgress<object>
enableRebase bool
res object[]

Returns

T

Type Parameters

T