StronglyTypedIdDefaultsAttribute Class

Configures the default values used by the strongly-typed identifier source generator for all the types of the assembly. Options set on StronglyTypedIdAttribute or StronglyTypedIdAttribute<T> take precedence over the values defined by this attribute.

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class StronglyTypedIdDefaultsAttribute : Attribute

Example

[assembly: StronglyTypedIdDefaults(GuidGenerationStrategy = GuidGenerationStrategy.Version7, GenerateNewtonsoftJsonConverter = false)]

// Usage:
var productId = ProductId.New(); // Uses Guid.CreateVersion7()
Console.WriteLine(productId.Value.Version); // 7

[StronglyTypedId<Guid>]
public partial struct ProductId
{
}
Inheritance
Attribute StronglyTypedIdDefaultsAttribute

Constructors

NameDescription
StronglyTypedIdDefaultsAttribute()

StronglyTypedIdDefaultsAttribute()

public StronglyTypedIdDefaultsAttribute()

No documentation is available.

Properties

NameDescription
AddCodeGeneratedAttributeGets or sets the default value indicating whether generated members are marked with GeneratedCodeAttribute. When the property is not set, the attribute is added.
GenerateMongoDBBsonSerializationGets or sets the default value indicating whether a MongoDB.Bson.Serialization.Serializers.SerializerBase{T} is generated. When the property is not set, the serializer is generated.
GenerateNewtonsoftJsonConverterGets or sets the default value indicating whether a Newtonsoft.Json.JsonConverter is generated. When the property is not set, the converter is generated.
GenerateSystemComponentModelTypeConverterGets or sets the default value indicating whether a System.ComponentModel.TypeConverter is generated. When the property is not set, the converter is generated.
GenerateSystemTextJsonConverterGets or sets the default value indicating whether a System.Text.Json.Serialization.JsonConverter is generated. When the property is not set, the converter is generated.
GenerateToStringAsRecordGets or sets the default value indicating whether the ToString() method generates output in record format. When the property is not set, the record format is used.
GuidGenerationStrategyGets or sets the default strategy used by the generated New() method when the underlying type is Guid. When the property is not set, GuidGenerationStrategy.Version4 is used.
StringComparisonGets or sets the default string comparison method to use when the underlying type is String. When the property is not set, StringComparison.Ordinal is used.

AddCodeGeneratedAttribute

StronglyTypedIdDefaultsAttribute.cs

Gets or sets the default value indicating whether generated members are marked with GeneratedCodeAttribute. When the property is not set, the attribute is added.

public bool AddCodeGeneratedAttribute { get; set; }

Property value

bool

GenerateMongoDBBsonSerialization

StronglyTypedIdDefaultsAttribute.cs

Gets or sets the default value indicating whether a MongoDB.Bson.Serialization.Serializers.SerializerBase{T} is generated. When the property is not set, the serializer is generated.

public bool GenerateMongoDBBsonSerialization { get; set; }

Property value

bool

GenerateNewtonsoftJsonConverter

StronglyTypedIdDefaultsAttribute.cs

Gets or sets the default value indicating whether a Newtonsoft.Json.JsonConverter is generated. When the property is not set, the converter is generated.

public bool GenerateNewtonsoftJsonConverter { get; set; }

Property value

bool

GenerateSystemComponentModelTypeConverter

StronglyTypedIdDefaultsAttribute.cs

Gets or sets the default value indicating whether a System.ComponentModel.TypeConverter is generated. When the property is not set, the converter is generated.

public bool GenerateSystemComponentModelTypeConverter { get; set; }

Property value

bool

GenerateSystemTextJsonConverter

StronglyTypedIdDefaultsAttribute.cs

Gets or sets the default value indicating whether a System.Text.Json.Serialization.JsonConverter is generated. When the property is not set, the converter is generated.

public bool GenerateSystemTextJsonConverter { get; set; }

Property value

bool

GenerateToStringAsRecord

StronglyTypedIdDefaultsAttribute.cs

Gets or sets the default value indicating whether the ToString() method generates output in record format. When the property is not set, the record format is used.

public bool GenerateToStringAsRecord { get; set; }

Property value

bool

Gets or sets the default strategy used by the generated New() method when the underlying type is Guid. When the property is not set, GuidGenerationStrategy.Version4 is used.

public GuidGenerationStrategy GuidGenerationStrategy { get; set; }

Gets or sets the default string comparison method to use when the underlying type is String. When the property is not set, StringComparison.Ordinal is used.

public StringComparison StringComparison { get; set; }

Property value

StringComparison