Class OperationFeature
A feature attached to a text variant generation operation. This adds metadata to the feature to drive its application to the operation context.
public record OperationFeature : Feature, IEquatable<Feature>, IEquatable<OperationFeature>
- Inheritance
-
OperationFeature
- Implements
- Inherited Members
Constructors
OperationFeature(string, string?, FeatureSetPolicy, bool, bool, bool)
Initializes a new instance of the OperationFeature class.
public OperationFeature(string name, string? value, FeatureSetPolicy setPolicy = FeatureSetPolicy.Multiple, bool isNegated = false, bool isGlobal = false, bool isShortLived = false)
Parameters
name
stringThe name.
value
stringThe value.
setPolicy
FeatureSetPolicyThe set policy.
isNegated
boolif set to
true
is negated.isGlobal
boolif set to
true
is global.isShortLived
boolif set to
true
is short-lived.
Exceptions
Properties
IsGlobal
Gets a value indicating whether this feature globally refers to the operation context as a whole, rather than to its affected nodes.
public bool IsGlobal { get; init; }
Property Value
IsNegated
Gets or sets a value indicating whether this feature is negated. A negated feature means that any existing feature with the same name should be removed.
public bool IsNegated { get; init; }
Property Value
IsShortLived
Gets or sets a value indicating whether this instance is short-lived. When true, the feature is removed on the next update.
public bool IsShortLived { get; init; }
Property Value
Methods
Parse(string)
Parses the specified text representing a feature, with syntax
name=value or name="value"
, where =
can be replaced by
:=
for a single feature or by ==
for a single-first
feature. When value is null, the text just contains the feature name.
public static OperationFeature Parse(string text)
Parameters
text
stringThe text.
Returns
- OperationFeature
Feature.
Exceptions
- ArgumentNullException
text
- FormatException
Invalid feature
ToString()
Converts to a parsable string with format !NAME^=VALUE
where
!
=negated, =global, and operator is
=
for
multiple, :=
for single, and ==
for single-first.
Value is enclosed in double quotes if it contains white spaces.
Suffix ^
is used for short-lived features.
public override string ToString()
Returns
TryParse(string, out OperationFeature?)
Tries parsing the specified feature.
public static bool TryParse(string text, out OperationFeature? feature)
Parameters
text
stringThe text representing the feature.
feature
OperationFeatureThe feature.
Returns
- bool
True if success.
Exceptions
UpdateFeature(OperationFeature, IList<OperationFeature>, bool)
Updates targets
features with source
feature. If source
is negated, the feature is removed
from targets
; otherwise, it is added or updated,
handling existing features with the same name according to the
source
set policy.
public static void UpdateFeature(OperationFeature source, IList<OperationFeature> targets, bool first)
Parameters
source
OperationFeatureThe source feature.
targets
IList<OperationFeature>The target features.
first
boolTrue if
source
is the first feature being added with that name in the context of a features set update.
Exceptions
- ArgumentNullException
source or targets