Class StringAttribute
This class can be used on a partial record struct
to source generate
a Primitively IString type that encapsulates a string value.
Inherited Members
Namespace: Primitively
Assembly: Primitively.Abstractions.dll
Syntax
[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class StringAttribute : PrimitiveAttribute
Remarks
The generated Primitively type will enforce the specified minimum and maximum length constraints.
Constructors
StringAttribute(int)
Initializes a new instance of the StringAttribute class with a fixed length.
Declaration
public StringAttribute(int length)
Parameters
Type | Name | Description |
---|---|---|
int | length | The fixed length of the string representation of the encapsulated primitive value. |
StringAttribute(int, int)
Initializes a new instance of the StringAttribute class with a specified minimum and maximum length.
Declaration
public StringAttribute(int minLength, int maxLength)
Parameters
Type | Name | Description |
---|---|---|
int | minLength | The minimum length of the string representation of the encapsulated primitive value. |
int | maxLength | The maximum length of the string representation of the encapsulated primitive value. |
Properties
Example
Gets or sets an optional example of the string representation of the encapsulated primitive value.
Declaration
public string? Example { get; set; }
Property Value
Type | Description |
---|---|
string | An example of the string representation of the encapsulated primitive value. |
Format
Gets or sets an optional format of the string representation of the encapsulated primitive value.
Declaration
public string? Format { get; set; }
Property Value
Type | Description |
---|---|
string | The format of the string representation of the encapsulated primitive value. |
MaxLength
Gets the maximum length of the string representation of the encapsulated primitive value.
Declaration
public int MaxLength { get; }
Property Value
Type | Description |
---|---|
int | The maximum length of the string representation of the encapsulated primitive value. |
MinLength
Gets the minimum length of the string representation of the encapsulated primitive value.
Declaration
public int MinLength { get; }
Property Value
Type | Description |
---|---|
int | The minimum length of the string representation of the encapsulated primitive value. |
Pattern
Gets or sets the optional regular expression pattern used to ensure that only valid values are encapsulated.
Declaration
public string? Pattern { get; set; }
Property Value
Type | Description |
---|---|
string | The regular expression pattern used to validate the encapsulated value. |