Game.UI.Menu.ModdingToolchainDependencyWriter
Assembly: Assembly-CSharp
Namespace: Game.UI.Menu
Type: class
Base: Colossal.UI.Binding.IWriter
Summary:
Serializes an IToolchainDependency instance into a JSON-ish writer (IJsonWriter) for UI/IPC consumption. Writes a type wrapper (using the runtime type full name) and several named properties that describe the dependency: name, state, progress, details, version and icon. If a null value is provided, the code writes a JSON null and then throws an ArgumentNullException (see "Exceptions" below).
Fields
- This class declares no instance fields.
Properties
- This class declares no public properties.
Constructors
public ModdingToolchainDependencyWriter()
The class has no explicit constructor in source; the compiler-provided default parameterless constructor is used.
Methods
public void Write(IJsonWriter writer, IToolchainDependency value)
Serializes the given IToolchainDependency to the provided IJsonWriter.
Behavior and written output: - If value is non-null: - Calls writer.TypeBegin(value.GetType().FullName) to begin a typed object using the dependency's runtime type full name. - Writes property "name" with value.localizedName. - Writes property "state" with (int)value.state.m_State (the integer underlying state value). - Writes property "progress" with value.state.m_Progress ?? (-1) (uses -1 when progress is null). - Writes property "details" with value.GetLocalizedState(includeProgress: false). - Writes property "version" with value.GetLocalizedVersion(). - Writes property "icon" with value.icon. - Calls writer.TypeEnd() and returns. - If value is null: - Calls writer.WriteNull(), then throws new ArgumentNullException("value", "Null passed to non-nullable value writer"). - Note: the method writes a null token to the writer but then throws; the exception prevents normal continuation.
Important notes / potential pitfalls: - The method assumes writer is non-null. Passing a null writer will produce a NullReferenceException before the ArgumentNullException for value can be observed. - Accessing value.state.m_State and value.state.m_Progress assumes value.state is non-null. If value.state is null, a NullReferenceException will be thrown. - The method records the runtime type (value.GetType().FullName) with TypeBegin, which preserves polymorphic type information when serializing. - "progress" uses -1 to indicate missing/unknown progress (because of the null-coalescing fallback).
Exceptions: - Throws ArgumentNullException when value is null (after writing a null token). - May throw NullReferenceException if writer is null or value.state is null.
Usage Example
// Example usage: serialize a toolchain dependency to an IJsonWriter
IJsonWriter jsonWriter = /* obtain a writer */;
IToolchainDependency dependency = /* obtain the dependency instance */;
var serializer = new Game.UI.Menu.ModdingToolchainDependencyWriter();
try
{
serializer.Write(jsonWriter, dependency);
}
catch (ArgumentNullException ex)
{
// Handle null dependency (note: the writer already received a null token before the exception)
}
Additional implementation details:
- Requires Colossal.UI.Binding for the IWriter