Class XFactory
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
Generators
XML-name → generator-function map for this factory instance. Populated
by each type's Reg(this) call. Concurrent so that parallel
Reg calls (e.g. independent test classes each booting the
registration graph) can TryAdd without corrupting the map.
public ConcurrentDictionary<string, XFactory.XGeneratorDelegate> Generators { get; }
Property Value
Methods
GenByChild<T>(XElement, string, IProgress<IMessage>, 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<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class
Parameters
Returns
- T
Type Parameters
T
GenByChild<T>(XElement, string, out string, IProgress<IMessage>, 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<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class
Parameters
srcXElementbaseDirectorystringrelFilestringprogressIProgress<IMessage>enableRebaseboolresobject[]
Returns
- T
Type Parameters
T
GenByFile<T>(string, string, IProgress<IMessage>, bool, object[])
Generates an object of type T from an XML file.
public static T GenByFile<T>(string baseDirectory, string relFile, IProgress<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class
Parameters
Returns
- T
Type Parameters
T
GenFileRefSourceByChild<T>(XElement, string, IProgress<IMessage>, bool, object[])
Generates a FileRefSource<T> from the first child element.
public static FileRefSource<T> GenFileRefSourceByChild<T>(XElement src, string baseDirectory, IProgress<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class, IMakeXmlSource
Parameters
Returns
Type Parameters
T
GenFileRefSourceByFile<T>(string, string, IProgress<IMessage>, bool, object[])
Generates a FileRefSource<T> from an XML file.
public static FileRefSource<T> GenFileRefSourceByFile<T>(string baseDirectory, string relFile, IProgress<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class, IMakeXmlSource
Parameters
Returns
Type Parameters
T
GenFileRefSource<T>(XElement, string, IProgress<IMessage>, bool, object[])
Generates a FileRefSource<T> from an XML element.
public static FileRefSource<T> GenFileRefSource<T>(XElement src, string baseDirectory, IProgress<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class, IMakeXmlSource
Parameters
Returns
Type Parameters
T
GenListSkippingUnloadable<T>(IEnumerable<XElement>, string, IProgress<IMessage>, 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<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class
Parameters
elementsIEnumerable<XElement>baseDirectorystringprogressIProgress<IMessage>enableRebaseboolresobject[]
Returns
- List<T>
Type Parameters
T
Gen<T>(XElement, string, IProgress<IMessage>, 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<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class
Parameters
Returns
- T
Type Parameters
T
Gen<T>(XElement, string, out string, IProgress<IMessage>, 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<IMessage> progress, bool enableRebase = true, object[] res = null) where T : class
Parameters
srcXElementbaseDirectorystringrelFilestringprogressIProgress<IMessage>enableRebaseboolresobject[]
Returns
- T
Type Parameters
T