Class UnitySnapshotValueParsers
Unity-specific utility methods for parsing and clamping system configuration snapshot values.
Provides safe value conversion with fallback handling for integer, float, and boolean data types.
Integrates with snapshot field accessors and transformation utilities for comprehensive data processing.
Ensures data integrity through robust parsing with culture-invariant formatting and boundary validation.
Inherited Members
Namespace: Serenity.SystemConfiguration.Infrastructure.Helpers
Assembly: Serenity.UnitySystemConfiguration.Infrastructure.dll
Syntax
public static class UnitySnapshotValueParsers
Methods
ClampFloat(float, float, float)
Clamps a float value between specified minimum and maximum bounds using Unity's Mathf utility.
Declaration
public static float ClampFloat(float v, float min, float max)
Parameters
| Type | Name | Description |
|---|---|---|
| float | v | Value to clamp |
| float | min | Minimum allowed value |
| float | max | Maximum allowed value |
Returns
| Type | Description |
|---|---|
| float | Clamped value within the specified bounds |
ClampInt(int, int, int)
Clamps an integer value between specified minimum and maximum bounds using Unity's Mathf utility.
Declaration
public static int ClampInt(int v, int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | v | Value to clamp |
| int | min | Minimum allowed value |
| int | max | Maximum allowed value |
Returns
| Type | Description |
|---|---|
| int | Clamped value within the specified bounds |
ParseFloatOr(string, float)
Safely parses a string to float with intelligent fallback to integer conversion.
Attempts float parsing first, then integer parsing as fallback option.
Uses culture-invariant formatting for consistent parsing across different system locales.
Declaration
public static float ParseFloatOr(string s, float fallback)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | String value to parse |
| float | fallback | Fallback value to return if parsing fails |
Returns
| Type | Description |
|---|---|
| float | Parsed float value or fallback if parsing unsuccessful |
ParseIntOr(string, int)
Safely parses a string to integer with intelligent fallback handling.
Attempts integer parsing first, then float parsing with floor conversion if needed.
Uses culture-invariant formatting for consistent parsing across different system locales.
Declaration
public static int ParseIntOr(string s, int fallback)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | String value to parse |
| int | fallback | Fallback value to return if parsing fails |
Returns
| Type | Description |
|---|---|
| int | Parsed integer value or fallback if parsing unsuccessful |
ReadBoolOrParse(ISystemConfigurationSnapshot, SnapshotKeyMap, string)
Reads and parses boolean values from system configuration snapshots with intelligent field handling.
Provides direct access for known boolean fields (compute shaders, ray tracing support) or string transformation and parsing for custom fields.
Uses robust parsing utilities with fallback to default value when parsing fails.
Declaration
public static bool ReadBoolOrParse(ISystemConfigurationSnapshot snap, SnapshotKeyMap map, string defStr)
Parameters
| Type | Name | Description |
|---|---|---|
| ISystemConfigurationSnapshot | snap | System configuration snapshot containing the data |
| SnapshotKeyMap | map | Field mapping configuration specifying source field and transformations |
| string | defStr | Default value as string if parsing fails |
Returns
| Type | Description |
|---|---|
| bool | Parsed boolean value from the snapshot or default if parsing unsuccessful |
ReadFloatOrParse(ISystemConfigurationSnapshot, SnapshotKeyMap, string, string, string)
Reads and parses float values from system configuration snapshots with string transformation support.
Applies configured string transformations before parsing and validates against specified boundaries.
Provides robust fallback handling with configurable minimum, maximum, and default value constraints.
Declaration
public static float ReadFloatOrParse(ISystemConfigurationSnapshot snap, SnapshotKeyMap map, string minStr, string maxStr, string defStr)
Parameters
| Type | Name | Description |
|---|---|---|
| ISystemConfigurationSnapshot | snap | System configuration snapshot containing the data |
| SnapshotKeyMap | map | Field mapping configuration specifying source field and transformations |
| string | minStr | Minimum allowed value as string (parsed with infinity fallback) |
| string | maxStr | Maximum allowed value as string (parsed with infinity fallback) |
| string | defStr | Default value as string if parsing fails |
Returns
| Type | Description |
|---|---|
| float | Parsed and clamped float value from the snapshot |
ReadIntOrParse(ISystemConfigurationSnapshot, SnapshotKeyMap, string, string, string)
Reads and parses integer values from system configuration snapshots with comprehensive validation.
Handles direct field access for known integer fields or string transformation and parsing for custom fields.
Applies boundary clamping with configurable minimum, maximum, and default value constraints.
Supports system memory, GPU memory, display dimensions, and refresh rate field types.
Declaration
public static int ReadIntOrParse(ISystemConfigurationSnapshot snap, SnapshotKeyMap map, string minStr, string maxStr, string defStr)
Parameters
| Type | Name | Description |
|---|---|---|
| ISystemConfigurationSnapshot | snap | System configuration snapshot containing the data |
| SnapshotKeyMap | map | Field mapping configuration specifying source field and transformations |
| string | minStr | Minimum allowed value as string (parsed with fallback) |
| string | maxStr | Maximum allowed value as string (parsed with fallback) |
| string | defStr | Default value as string if parsing fails |
Returns
| Type | Description |
|---|---|
| int | Parsed and clamped integer value from the snapshot |