Class FieldExtensions
- Namespace
- MonkeyLoader.Resonite
- Assembly
- MonkeyLoader.Resonite.Integration.dll
Contains extension methods for fields and other world elements
public static class FieldExtensions
- Inheritance
-
FieldExtensions
- Inherited Members
Fields
WriteBackPrefix
The prefix for the SetValue
eventLabel used when the cause is a change in the synchronized field's shared value.
public const string WriteBackPrefix = "SyncedField.WriteBack"
Field Value
Remarks
The actually passed label has the following format:
$"{WriteBackPrefix}.{field.FrooxEngine.World.GetIdentifier()}"
Methods
GetReferenceLabel(IWorldElement?)
Creates a label describing the target reference as a FrooxEngine.RefEditor would.
public static string GetReferenceLabel(this IWorldElement? target)
Parameters
targetIWorldElementThe reference to label.
Returns
- string
A label for the
targetreference if it is notnull; otherwise,<i>null</i>.
SyncWithConfigKeyEnumFlagUntyped<T>(IField<bool>, IDefiningConfigKey, T, string?, bool)
Synchronizes the field's boolean
Value with whether the configKey's
value has the referenceValue flag set.
If the configKey value is null,
the field's will always be set to false.
This method is mainly public for reflection based use,
to simplify handling nullable values.
In theory, the configKey could be any (nullable) enum or even integer type.
public static Action<IChangeable> SyncWithConfigKeyEnumFlagUntyped<T>(this IField<bool> field, IDefiningConfigKey configKey, T referenceValue, string? eventLabel = null, bool allowWriteBack = true) where T : unmanaged, Enum
Parameters
fieldIField<bool>The field to synchronize with.
configKeyIDefiningConfigKeyThe config key to synchronize with.
referenceValueTThe flag that is checked for in the
configKey's value.eventLabelstringOptional override for the event label passed when writing back a change of the field.
Defaults to:$"SyncedField.WriteBack.{field.World.GetIdentifier()}"allowWriteBackboolWhether changes of the
fieldshould be written back to the config key.
Returns
- Action<IChangeable>
The delegate subscribed to the
field's Changed event.
Type Parameters
TThe type of the field's value.
Remarks
When allowWriteBack is true,
changes to the field get written back to the config key.
If allowWriteBack is false or
setting the value fails,
the field's value is reset back to the config key's value.
The eventLabel is passed when
setting the value of the config key.
It defaults to: $"{WriteBackPrefix}.{
field.World.GetIdentifier()}"
SyncWithConfigKeyEnumFlag<T>(IField<bool>, IDefiningConfigKey<T?>, T, string?, bool)
Synchronizes the field's boolean
Value with whether the configKey's
value has the referenceValue flag set.
When the configKey value is null,
the field's will always be set to false.
public static Action<IChangeable> SyncWithConfigKeyEnumFlag<T>(this IField<bool> field, IDefiningConfigKey<T?> configKey, T referenceValue, string? eventLabel = null, bool allowWriteBack = true) where T : unmanaged, Enum
Parameters
fieldIField<bool>The field to synchronize with.
configKeyIDefiningConfigKey<T?>The config key to synchronize with.
referenceValueTThe flag that is checked for in the
configKey's value.eventLabelstringOptional override for the event label passed when writing back a change of the field.
Defaults to:$"SyncedField.WriteBack.{field.World.GetIdentifier()}"allowWriteBackboolWhether changes of the
fieldshould be written back to the config key.
Returns
- Action<IChangeable>
The delegate subscribed to the
field's Changed event.
Type Parameters
TThe type of the field's value.
Remarks
When allowWriteBack is true,
changes to the field get written back to the config key.
If allowWriteBack is false or
setting the value fails,
the field's value is reset back to the config key's value.
The eventLabel is passed when
setting the value of the config key.
It defaults to: $"{WriteBackPrefix}.{
field.World.GetIdentifier()}"
SyncWithConfigKeyEnumFlag<T>(IField<bool>, IDefiningConfigKey<T>, T, string?, bool)
Synchronizes the field's boolean
Value with whether the configKey's
value has the referenceValue flag set.
public static Action<IChangeable> SyncWithConfigKeyEnumFlag<T>(this IField<bool> field, IDefiningConfigKey<T> configKey, T referenceValue, string? eventLabel = null, bool allowWriteBack = true) where T : unmanaged, Enum
Parameters
fieldIField<bool>The field to synchronize with.
configKeyIDefiningConfigKey<T>The config key to synchronize with.
referenceValueTThe flag that is checked for in the
configKey's value.eventLabelstringOptional override for the event label passed when writing back a change of the field.
Defaults to:$"SyncedField.WriteBack.{field.World.GetIdentifier()}"allowWriteBackboolWhether changes of the
fieldshould be written back to the config key.
Returns
- Action<IChangeable>
The delegate subscribed to the
field's Changed event.
Type Parameters
TThe type of the field's value.
Remarks
When allowWriteBack is true,
changes to the field get written back to the config key.
If allowWriteBack is false or
setting the value fails,
the field's value is reset back to the config key's value.
The eventLabel is passed when
setting the value of the config key.
It defaults to: $"{WriteBackPrefix}.{
field.World.GetIdentifier()}"
SyncWithConfigKeyUntyped<T>(IField<T>, IDefiningConfigKey, string?, bool)
Synchronizes the field's (nullable)
Value with that of the configKey.
This method is mainly public for reflection based use, to simplify handling nullable values.
public static Action<IChangeable> SyncWithConfigKeyUntyped<T>(this IField<T> field, IDefiningConfigKey configKey, string? eventLabel = null, bool allowWriteBack = true)
Parameters
fieldIField<T>The field to synchronize with.
configKeyIDefiningConfigKeyThe config key to synchronize with.
eventLabelstringOptional override for the event label passed when writing back a change of the field.
Defaults to:$"SyncedField.WriteBack.{field.World.GetIdentifier()}"allowWriteBackboolWhether changes of the
fieldshould be written back to the config key.
Returns
- Action<IChangeable>
The delegate subscribed to the
field's Changed event.
Type Parameters
TThe type of the field's value.
Remarks
When allowWriteBack is true,
changes to the field get written back to the config key.
If allowWriteBack is false or
setting the value fails,
the field's value is reset back to the config key's value.
The eventLabel is passed when
setting the value of the config key.
It defaults to: $"{WriteBackPrefix}.{
field.World.GetIdentifier()}"
SyncWithConfigKey<T>(IField<T?>, IDefiningConfigKey<T?>, string?, bool)
Synchronizes the field's nullable
Value with that of the configKey.
public static Action<IChangeable> SyncWithConfigKey<T>(this IField<T?> field, IDefiningConfigKey<T?> configKey, string? eventLabel = null, bool allowWriteBack = true) where T : struct
Parameters
fieldIField<T?>The field to synchronize with.
configKeyIDefiningConfigKey<T?>The config key to synchronize with.
eventLabelstringOptional override for the event label passed when writing back a change of the field.
Defaults to:$"SyncedField.WriteBack.{field.World.GetIdentifier()}"allowWriteBackboolWhether changes of the
fieldshould be written back to the config key.
Returns
- Action<IChangeable>
The delegate subscribed to the
field's Changed event.
Type Parameters
TThe type of the field's value.
Remarks
When allowWriteBack is true,
changes to the field get written back to the config key.
If allowWriteBack is false or
setting the value fails,
the field's value is reset back to the config key's value.
The eventLabel is passed when
setting the value of the config key.
It defaults to: $"{WriteBackPrefix}.{
field.World.GetIdentifier()}"
SyncWithConfigKey<T>(IField<T>, IDefiningConfigKey<T>, string?, bool)
Synchronizes the field's Value with that of the configKey.
public static Action<IChangeable> SyncWithConfigKey<T>(this IField<T> field, IDefiningConfigKey<T> configKey, string? eventLabel = null, bool allowWriteBack = true)
Parameters
fieldIField<T>The field to synchronize with.
configKeyIDefiningConfigKey<T>The config key to synchronize with.
eventLabelstringOptional override for the event label passed when writing back a change of the field.
Defaults to:$"SyncedField.WriteBack.{field.World.GetIdentifier()}"allowWriteBackboolWhether changes of the
fieldshould be written back to the config key.
Returns
- Action<IChangeable>
The delegate subscribed to the
field's Changed event.
Type Parameters
TThe type of the field's value.
Remarks
When allowWriteBack is true,
changes to the field get written back to the config key.
If allowWriteBack is false or
setting the value fails,
the field's value is reset back to the config key's value.
The eventLabel is passed when
setting the value of the config key.
It defaults to: $"{WriteBackPrefix}.{
field.World.GetIdentifier()}"
SyncWithNullableConfigKeyHasValue<T>(IField<bool>, IDefiningConfigKey<T?>, string?, bool)
Synchronizes this field's Value with
the HasValue of the configKey.
When the field is toggled to true or set to false,
the Value is set to default(.T)
public static Action<IChangeable> SyncWithNullableConfigKeyHasValue<T>(this IField<bool> field, IDefiningConfigKey<T?> configKey, string? eventLabel = null, bool allowWriteBack = true) where T : struct
Parameters
fieldIField<bool>The field to synchronize with.
configKeyIDefiningConfigKey<T?>The config key to synchronize with.
eventLabelstringOptional override for the event label passed when writing back a change of the field.
Defaults to:$"SyncedField.WriteBack.{field.World.GetIdentifier()}"allowWriteBackboolWhether changes of the
fieldshould be written back to the config key.
Returns
- Action<IChangeable>
The delegate subscribed to the
field's Changed event.
Type Parameters
TThe type of the field's value.
Remarks
When allowWriteBack is true,
changes to the field get written back to the config key.
If allowWriteBack is false or
setting the value fails,
the field's value is reset back to the config key's value.
The eventLabel is passed when
setting the value of the config key.
It defaults to: $"{WriteBackPrefix}.{
field.World.GetIdentifier()}"