Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Vogen.SharedTypes/StringComparisonDefault.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Diagnostics;
// ReSharper disable UnusedMember.Global

namespace Vogen;

public enum StringComparisonDefault
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Unspecified = -1,
Omit = 0,
Ordinal = 1,
OrdinalIgnoreCase = 2,
CurrentCulture = 3,
CurrentCultureIgnoreCase = 4,
InvariantCulture = 5,
InvariantCultureIgnoreCase = 6,
}
136 changes: 132 additions & 4 deletions src/Vogen.SharedTypes/ValueObjectAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ReSharper disable UnusedParameter.Local
// ReSharper disable UnusedParameter.Local
// ReSharper disable NullableWarningSuppressionIsUsed
// ReSharper disable UnusedType.Global

Expand Down Expand Up @@ -88,6 +88,78 @@ public ValueObjectAttribute(
numericsGeneration)
{
}

/// <summary>
/// Configures aspects of this individual value object.
/// </summary>
/// <param name="conversions">Specifies what conversion code is generated - defaults to <see cref="Conversions.Default"/> which generates type converters and a converter to handle serialization using System.Text.Json</param>
/// <param name="throws">Specifies the type of exception thrown when validation fails—defaults to <see cref="ValueObjectValidationException"/>.</param>
/// <param name="customizations">Simple customization switches—defaults to <see cref="Customizations.None"/>.</param>
/// <param name="deserializationStrictness">Specifies how strict deserialization is, e.g. should your Validate method be called, or should pre-defined instances that otherwise invalid be allowed - defaults to <see cref="DeserializationStrictness.AllowValidAndKnownInstances"/>.</param>
/// <param name="debuggerAttributes">Specifies the level that debug attributes are written as some IDEs don't support all of them, e.g., Rider - defaults to <see cref="DebuggerAttributeGeneration.Full"/> which generates DebuggerDisplay and a debugger proxy type for IDEs that support them</param>
/// <param name="comparison">Species which comparison code is generated—defaults to <see cref="ComparisonGeneration.UseUnderlying"/> which hoists any IComparable implementations from the primitive.</param>
/// <param name="stringComparers">Specifies which string comparison code is generated—defaults to <see cref="StringComparersGeneration.Omit"/> which doesn't generate anything related to string comparison.</param>
/// <param name="toPrimitiveCasting">Controls how cast operators are generated for casting from the Value Object to the primitive.
/// Options are implicit or explicit or none. Explicit is preferred over implicit if you really need them, but isn't recommended.
/// See <see href="https://github.com/SteveDunn/Vogen/wiki/Casting"/> for more information.</param>
/// <param name="fromPrimitiveCasting">Controls how cast operators are generated for casting from the primitive to the Value Object.
/// Options are implicit or explicit or none. Explicit is preferred over implicit if you really need them, but isn't recommended.
/// See <see href="https://github.com/SteveDunn/Vogen/wiki/Casting"/> for more information.
/// </param>
/// <param name="parsableForStrings">Specifies what is generated for IParsable types for strings - defaults to <see cref="ParsableForStrings.GenerateMethodsAndInterface"/>.</param>
/// <param name="parsableForPrimitives">Specifies what is generated for Parse and TryParse methods - defaults to <see cref="ParsableForPrimitives.HoistMethodsAndInterfaces"/>.</param>
/// <param name="tryFromGeneration">Specifies what to write for TryFrom methods—defaults to <see cref="TryFromGeneration.GenerateBoolAndErrorOrMethods"/>.</param>
/// <param name="isInitializedMethodGeneration">Specifies whether to generate an IsInitialized() method - defaults to <see cref="IsInitializedMethodGeneration.Generate"/>.</param>
/// <param name="primitiveEqualityGeneration">
/// Specifies whether to generate primitive comparison operators, allowing this type to be compared for equality to the primitive.
/// Defaults to <see cref="PrimitiveEqualityGeneration.GenerateOperatorsAndMethods"/>
/// <example>
/// <para>
/// var vo = MyInt.From(123);
/// </para>
/// <para>
/// bool same = vo == 123;
/// </para>
/// </example>
/// </param>
/// <param name="numericsGeneration">Specifies whether to generate numeric interfaces (<c>INumber&lt;T&gt;</c> or <c>INumberBase&lt;T&gt;</c> depending on the underlying type)—defaults to <see cref="NumericsGeneration.Omit"/>.</param>
/// <param name="stringDefaultComparison">Specifies the default <see cref="StringComparisonDefault"/> used for <c>==</c>, <c>Equals</c>, and <c>GetHashCode</c> on string-backed value objects—defaults to <see cref="StringComparisonDefault.Omit"/> which uses the underlying string's default comparison.</param>
public ValueObjectAttribute(
Conversions conversions,
Type? throws,
Customizations customizations,
DeserializationStrictness deserializationStrictness,
DebuggerAttributeGeneration debuggerAttributes,
ComparisonGeneration comparison,
StringComparersGeneration stringComparers,
CastOperator toPrimitiveCasting,
CastOperator fromPrimitiveCasting,
ParsableForStrings parsableForStrings,
ParsableForPrimitives parsableForPrimitives,
TryFromGeneration tryFromGeneration,
IsInitializedMethodGeneration isInitializedMethodGeneration,
PrimitiveEqualityGeneration primitiveEqualityGeneration,
NumericsGeneration numericsGeneration,
StringComparisonDefault stringDefaultComparison) : base(
typeof(T),
conversions,
throws,
customizations,
deserializationStrictness,
debuggerAttributes,
comparison,
stringComparers,
toPrimitiveCasting,
fromPrimitiveCasting,
parsableForStrings,
parsableForPrimitives,
tryFromGeneration,
isInitializedMethodGeneration,
primitiveEqualityGeneration,
numericsGeneration,
stringDefaultComparison)
{
}
}

/// <summary>
Expand All @@ -100,9 +172,9 @@ public class ValueObjectAttribute : Attribute
// keep this signature in-line with `VogenConfiguration`
// as the syntax/semantics are read in the generator
// using parameter indexes (i.e. it expected param 0 to be the underlying type etc).

// ReSharper disable once MemberCanBeProtected.Global

/// <summary>
/// Configures aspects of this individual value object.
/// </summary>
Expand Down Expand Up @@ -156,5 +228,61 @@ public ValueObjectAttribute(
// of parameters is a binary-breaking change. See https://github.com/dotnet/runtime/issues/103722
// for more information.
}

/// <summary>
/// Configures aspects of this individual value object.
/// </summary>
/// <param name="underlyingType">The type of the primitive that is being wrapped—defaults to int.</param>
/// <param name="conversions">Specifies what conversion code is generated - defaults to <see cref="Conversions.Default"/> which generates type converters and a converter to handle serialization using System.Text.Json</param>
/// <param name="throws">Specifies the type of exception thrown when validation fails—defaults to <see cref="ValueObjectValidationException"/>.</param>
/// <param name="customizations">Simple customization switches—defaults to <see cref="Customizations.None"/>.</param>
/// <param name="deserializationStrictness">Specifies how strict deserialization is, e.g. should your Validate method be called, or should pre-defined instances that otherwise invalid be allowed - defaults to <see cref="DeserializationStrictness.AllowValidAndKnownInstances"/>.</param>
/// <param name="debuggerAttributes">Specifies the level that debug attributes are written as some IDEs don't support all of them, e.g., Rider - defaults to <see cref="DebuggerAttributeGeneration.Full"/> which generates DebuggerDisplay and a debugger proxy type for IDEs that support them</param>
/// <param name="comparison">Species which comparison code is generated—defaults to <see cref="ComparisonGeneration.UseUnderlying"/> which hoists any IComparable implementations from the primitive.</param>
/// <param name="stringComparers">Specifies which string comparison code is generated—defaults to <see cref="StringComparersGeneration.Omit"/> which doesn't generate anything related to string comparison.</param>
/// <param name="toPrimitiveCasting">Specifies the type of casting from wrapper to primitive - defaults to <see cref="CastOperator.Explicit"/>.</param>
/// <param name="fromPrimitiveCasting">Specifies the type of casting from primitive to wrapper - default to <see cref="CastOperator.Explicit"/>.</param>
/// <param name="parsableForStrings">Specifies what is generated for IParsable types for strings - defaults to <see cref="ParsableForStrings.GenerateMethodsAndInterface"/>.</param>
/// <param name="parsableForPrimitives">Specifies what is generated for Parse and TryParse methods - defaults to <see cref="ParsableForPrimitives.HoistMethodsAndInterfaces"/>.</param>
/// <param name="tryFromGeneration">Specifies what to write for TryFrom methods—defaults to <see cref="TryFromGeneration.GenerateBoolAndErrorOrMethods"/>.</param>
/// <param name="isInitializedMethodGeneration">Specifies whether to generate an IsInitialized() method - defaults to <see cref="IsInitializedMethodGeneration.Generate"/>.</param>
/// <param name="primitiveEqualityGeneration">
/// Specifies whether to generate primitive comparison operators, allowing this type to be compared for equality to the primitive.
/// Defaults to <see cref="PrimitiveEqualityGeneration.GenerateOperatorsAndMethods"/>
/// <example>
/// <para>
/// var vo = MyInt.From(123);
/// </para>
/// <para>
/// bool same = vo == 123;
/// </para>
/// </example>
/// </param>
/// <param name="numericsGeneration">Specifies whether to generate numeric interfaces (<c>INumber&lt;T&gt;</c> or <c>INumberBase&lt;T&gt;</c> depending on the underlying type)—defaults to <see cref="NumericsGeneration.Omit"/>.</param>
/// <param name="stringDefaultComparison">Specifies the default <see cref="StringComparisonDefault"/> used for <c>==</c>, <c>Equals</c>, and <c>GetHashCode</c> on string-backed value objects—defaults to <see cref="StringComparisonDefault.Omit"/> which uses the underlying string's default comparison.</param>
public ValueObjectAttribute(
Type? underlyingType,
Conversions conversions,
Type? throws,
Customizations customizations,
DeserializationStrictness deserializationStrictness,
DebuggerAttributeGeneration debuggerAttributes,
ComparisonGeneration comparison,
StringComparersGeneration stringComparers,
CastOperator toPrimitiveCasting,
CastOperator fromPrimitiveCasting,
ParsableForStrings parsableForStrings,
ParsableForPrimitives parsableForPrimitives,
TryFromGeneration tryFromGeneration,
IsInitializedMethodGeneration isInitializedMethodGeneration,
PrimitiveEqualityGeneration primitiveEqualityGeneration,
NumericsGeneration numericsGeneration,
StringComparisonDefault stringDefaultComparison)
{
// DO NOT ADD PARAMETERS HERE, INSTEAD, CREATE OVERLOADS (at least until a new major version).
// This is because some users use reflection to find this attribute, and changing the amount
// of parameters is a binary-breaking change. See https://github.com/dotnet/runtime/issues/103722
// for more information.
}
}
}
}
66 changes: 65 additions & 1 deletion src/Vogen.SharedTypes/VogenDefaultsAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ReSharper disable MemberInitializerValueIgnored
// ReSharper disable MemberInitializerValueIgnored
// ReSharper disable UnusedType.Global

// ReSharper disable UnusedParameter.Local
Expand Down Expand Up @@ -76,4 +76,68 @@ public VogenDefaultsAttribute(
NumericsGeneration numericsGeneration = NumericsGeneration.Unspecified)
{
}

/// <summary>
/// Creates a new instance of a type that represents the default
/// values used for value object generation.
/// </summary>
/// <param name="underlyingType">The type of the primitive that is being wrapped—defaults to int.</param>
/// <param name="conversions">Specifies what conversion code is generated - defaults to <see cref="Conversions.Default"/> which generates type converters and a converter to handle serialization using System.Text.Json</param>
/// <param name="throws">Specifies the type of exception thrown when validation fails—defaults to <see cref="ValueObjectValidationException"/>.</param>
/// <param name="customizations">Simple customization switches—defaults to <see cref="Customizations.None"/>.</param>
/// <param name="deserializationStrictness">Specifies how strict deserialization is, e.g. should your Validate method be called, or should pre-defined instances that otherwise invalid be allowed - defaults to <see cref="DeserializationStrictness.AllowValidAndKnownInstances"/>.</param>
/// <param name="debuggerAttributes">Specifies the level that debug attributes are written as some IDEs don't support all of them, e.g., Rider - defaults to <see cref="DebuggerAttributeGeneration.Full"/> which generates DebuggerDisplay and a debugger proxy type for IDEs that support them</param>
/// <param name="toPrimitiveCasting">Controls how cast operators are generated for casting from the Value Object to the primitive.
/// Options are implicit or explicit or none. Explicit is preferred over implicit if you really need them, but isn't recommended.
/// See <see href="https://github.com/SteveDunn/Vogen/wiki/Casting"/> for more information.</param>
/// <param name="fromPrimitiveCasting">Controls how cast operators are generated for casting from the primitive to the Value Object.
/// Options are implicit or explicit or none. Explicit is preferred over implicit if you really need them, but isn't recommended.
/// See &lt;see href="https://github.com/SteveDunn/Vogen/wiki/Casting"/&gt; for more information.</param>
/// <param name="disableStackTraceRecordingInDebug">disables stack trace recording; in Debug builds, a stack trace is recorded and is
/// thrown in the exception when something is created in an uninitialized state, e.g. after deserialization</param>
/// <param name="parsableForStrings">Specifies what is generated for IParsable types for strings - defaults to <see cref="ParsableForStrings.GenerateMethodsAndInterface"/>.</param>
/// <param name="parsableForPrimitives">Specifies what is generated for Parse and TryParse methods - defaults to <see cref="ParsableForPrimitives.HoistMethodsAndInterfaces"/>.</param>
/// <param name="tryFromGeneration">Specifies what to write for TryFrom methods—defaults to <see cref="TryFromGeneration.GenerateBoolAndErrorOrMethods"/>.</param>
/// <param name="isInitializedMethodGeneration">Specifies whether to generate an IsInitialized() method - defaults to <see cref="IsInitializedMethodGeneration.Generate"/>.</param>
/// <param name="primitiveEqualityGeneration">
/// Specifies whether to generate primitive comparison operators, allowing this type to be compared for equality to the primitive.
/// Defaults to <see cref="PrimitiveEqualityGeneration.GenerateOperatorsAndMethods"/>
/// <example>
/// <para>
/// var vo = MyInt.From(123);
/// </para>
/// <para>
/// bool same = vo == 123;
/// </para>
/// </example>
/// </param>
/// <param name="systemTextJsonConverterFactoryGeneration">Controls the generation of the type factory for System.Text.Json.</param>
/// <param name="staticAbstractsGeneration">Controls the generation of static abstract interfaces.</param>
/// <param name="openApiSchemaCustomizations">Controls the generation of a Swashbuckle schema filter for OpenAPI.</param>
/// <param name="explicitlySpecifyTypeInValueObject">Every ValueObject attribute must explicitly specify the type of the primitive.</param>
/// <param name="numericsGeneration">Specifies whether to generate numeric interfaces (<c>INumber&lt;T&gt;</c> or <c>INumberBase&lt;T&gt;</c> depending on the underlying type)—defaults to <see cref="NumericsGeneration.Omit"/>.</param>
/// <param name="stringDefaultComparison">Specifies the default <see cref="StringComparisonDefault"/> used for <c>==</c>, <c>Equals</c>, and <c>GetHashCode</c> on string-backed value objects—defaults to <see cref="StringComparisonDefault.Omit"/> which uses the underlying string's default comparison.</param>
public VogenDefaultsAttribute(
Type? underlyingType,
Conversions conversions,
Type? throws,
Customizations customizations,
DeserializationStrictness deserializationStrictness,
DebuggerAttributeGeneration debuggerAttributes,
CastOperator toPrimitiveCasting,
CastOperator fromPrimitiveCasting,
bool disableStackTraceRecordingInDebug,
ParsableForStrings parsableForStrings,
ParsableForPrimitives parsableForPrimitives,
TryFromGeneration tryFromGeneration,
IsInitializedMethodGeneration isInitializedMethodGeneration,
SystemTextJsonConverterFactoryGeneration systemTextJsonConverterFactoryGeneration,
StaticAbstractsGeneration staticAbstractsGeneration,
OpenApiSchemaCustomizations openApiSchemaCustomizations,
bool explicitlySpecifyTypeInValueObject,
PrimitiveEqualityGeneration primitiveEqualityGeneration,
NumericsGeneration numericsGeneration,
StringComparisonDefault stringDefaultComparison)
{
}
}
Loading
Loading