diff --git a/src/Vogen.SharedTypes/ValueObjectAttribute.cs b/src/Vogen.SharedTypes/ValueObjectAttribute.cs index b194ca4d56..bb286df251 100644 --- a/src/Vogen.SharedTypes/ValueObjectAttribute.cs +++ b/src/Vogen.SharedTypes/ValueObjectAttribute.cs @@ -16,6 +16,38 @@ public class ValueObjectAttribute : ValueObjectAttribute // 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. + /// + /// Configures aspects of this individual value object. + /// + /// Specifies what conversion code is generated - defaults to which generates type converters and a converter to handle serialization using System.Text.Json + /// Specifies the type of exception thrown when validation fails—defaults to . + /// Simple customization switches—defaults to . + /// 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 . + /// Specifies the level that debug attributes are written as some IDEs don't support all of them, e.g., Rider - defaults to which generates DebuggerDisplay and a debugger proxy type for IDEs that support them + /// Species which comparison code is generated—defaults to which hoists any IComparable implementations from the primitive. + /// Specifies which string comparison code is generated—defaults to which doesn't generate anything related to string comparison. + /// 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 for more information. + /// 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. + /// Specifies what is generated for IParsable types for strings - defaults to . + /// Specifies what is generated for Parse and TryParse methods - defaults to . + /// Specifies what to write for TryFrom methods—defaults to . + /// Specifies whether to generate an IsInitialized() method - defaults to . + /// + /// Specifies whether to generate primitive comparison operators, allowing this type to be compared for equality to the primitive. + /// Defaults to + /// + /// + /// var vo = MyInt.From(123); + /// + /// + /// bool same = vo == 123; + /// + /// + /// public ValueObjectAttribute( Conversions conversions = Conversions.Default, Type? throws = null!, @@ -51,7 +83,7 @@ public ValueObjectAttribute( } /// - /// Marks a type as a Value Object. The type that this is applied to should be partial so that the + /// MMMarks a type as a Value Object. The type that this is applied to should be partial so that the /// source generator can augment it with equality, creation barriers, and any conversions. /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] @@ -61,6 +93,35 @@ public class ValueObjectAttribute : Attribute // 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 + /// + /// Configures aspects of this individual value object. + /// + /// The type of the primitive that is being wrapped—defaults to int. + /// Specifies what conversion code is generated - defaults to which generates type converters and a converter to handle serialization using System.Text.Json + /// Specifies the type of exception thrown when validation fails—defaults to . + /// Simple customization switches—defaults to . + /// 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 . + /// Specifies the level that debug attributes are written as some IDEs don't support all of them, e.g., Rider - defaults to which generates DebuggerDisplay and a debugger proxy type for IDEs that support them + /// Species which comparison code is generated—defaults to which hoists any IComparable implementations from the primitive. + /// Specifies which string comparison code is generated—defaults to which doesn't generate anything related to string comparison. + /// Specifies the type of casting from wrapper to primitive - defaults to . + /// Specifies the type of casting from primitive to wrapper - default to . + /// Specifies what is generated for IParsable types for strings - defaults to . + /// Specifies what is generated for Parse and TryParse methods - defaults to . + /// Specifies what to write for TryFrom methods—defaults to . + /// Specifies whether to generate an IsInitialized() method - defaults to . + /// + /// Specifies whether to generate primitive comparison operators, allowing this type to be compared for equality to the primitive. + /// Defaults to + /// + /// + /// var vo = MyInt.From(123); + /// + /// + /// bool same = vo == 123; + /// + /// + /// public ValueObjectAttribute( Type? underlyingType = null!, Conversions conversions = Conversions.Default, diff --git a/src/Vogen.SharedTypes/ValueObjectOrError.cs b/src/Vogen.SharedTypes/ValueObjectOrError.cs index 5c027e8565..4389a51925 100644 --- a/src/Vogen.SharedTypes/ValueObjectOrError.cs +++ b/src/Vogen.SharedTypes/ValueObjectOrError.cs @@ -52,7 +52,6 @@ public ValueObjectOrError(Validation error) /// /// Returns the wrapper, or throws an exception if the result failed. /// - /// The type of the wrapper. /// Throw when this type holds an error. public T ValueObject => _isSuccess ? _valueObject : throw new System.InvalidOperationException("Cannot access the value object as it is not valid: " + _error!.ErrorMessage); diff --git a/src/Vogen.SharedTypes/Vogen.SharedTypes.csproj b/src/Vogen.SharedTypes/Vogen.SharedTypes.csproj index 6ae1cd1972..c3fcdc310a 100644 --- a/src/Vogen.SharedTypes/Vogen.SharedTypes.csproj +++ b/src/Vogen.SharedTypes/Vogen.SharedTypes.csproj @@ -5,4 +5,10 @@ Vogen false + + bin\Debug\Vogen.SharedTypes.xml + + + bin\Release\Vogen.SharedTypes.xml + diff --git a/src/Vogen.SharedTypes/VogenDefaultsAttribute.cs b/src/Vogen.SharedTypes/VogenDefaultsAttribute.cs index de8a9c30e9..861ccf1693 100644 --- a/src/Vogen.SharedTypes/VogenDefaultsAttribute.cs +++ b/src/Vogen.SharedTypes/VogenDefaultsAttribute.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedType.Global // ReSharper disable UnusedParameter.Local + namespace Vogen; using System; @@ -17,12 +18,12 @@ public class VogenDefaultsAttribute : Attribute /// Creates a new instance of a type that represents the default /// values used for value object generation. /// - /// The primitive underlying type. - /// Any conversions that need to be done for this type, e.g. to be serialized etc. - /// The type of exception that is thrown when validation fails. - /// Any customizations, for instance, treating numbers in [de]serialization as strings. - /// The strictness of validation when deserializing. - /// Controls how debugger attributes are generated. This is useful in Rider where the attributes crash Rider's debugger. + /// The type of the primitive that is being wrapped—defaults to int. + /// Specifies what conversion code is generated - defaults to which generates type converters and a converter to handle serialization using System.Text.Json + /// Specifies the type of exception thrown when validation fails—defaults to . + /// Simple customization switches—defaults to . + /// 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 . + /// Specifies the level that debug attributes are written as some IDEs don't support all of them, e.g., Rider - defaults to which generates DebuggerDisplay and a debugger proxy type for IDEs that support them /// 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 for more information. @@ -31,15 +32,26 @@ public class VogenDefaultsAttribute : Attribute /// See <see href="https://github.com/SteveDunn/Vogen/wiki/Casting"/> for more information. /// 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 - /// Specifies the functionality around parsing (IParsable etc.) - /// Specifies the functionality around parsing (IParsable etc.) - /// Controls what is generated for the TryFrom methods. - /// Controls whether the IsInitialized method is generated. + /// Specifies what is generated for IParsable types for strings - defaults to . + /// Specifies what is generated for Parse and TryParse methods - defaults to . + /// Specifies what to write for TryFrom methods—defaults to . + /// Specifies whether to generate an IsInitialized() method - defaults to . + /// + /// Specifies whether to generate primitive comparison operators, allowing this type to be compared for equality to the primitive. + /// Defaults to + /// + /// + /// var vo = MyInt.From(123); + /// + /// + /// bool same = vo == 123; + /// + /// + /// /// Controls the generation of the type factory for System.Text.Json. /// Controls the generation of static abstract interfaces. /// Controls the generation of a Swashbuckle schema filter for OpenAPI. /// Every ValueObject attribute must explicitly specify the type of the primitive. - /// Whether or not to generate primitive comparison operators. public VogenDefaultsAttribute( Type? underlyingType = null, Conversions conversions = Conversions.Default, diff --git a/tests/Testbench/Program.cs b/tests/Testbench/Program.cs index 8e1a221105..84c3859f25 100644 --- a/tests/Testbench/Program.cs +++ b/tests/Testbench/Program.cs @@ -1,7 +1,11 @@ using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.IO; +using System.Linq; using System.Xml.Serialization; using Vogen; +// ReSharper disable UnusedVariable [assembly: VogenDefaults( openApiSchemaCustomizations: OpenApiSchemaCustomizations.GenerateSwashbuckleSchemaFilter | @@ -11,10 +15,11 @@ namespace Testbench; + [ValueObject(conversions: Conversions.XmlSerializable)] public partial class MyShort; -[ValueObject(conversions: Conversions.XmlSerializable)] +[ValueObject(conversions: Conversions.XmlSerializable, primitiveEqualityGeneration: PrimitiveEqualityGeneration.GenerateOperatorsAndMethods)] public partial class MyInt; [ValueObject] @@ -43,11 +48,18 @@ public static class Program { public static void Main() { + MyInt i1 = MyInt.From(100); + MyInt i2 = MyInt.From(200); + bool smaller = i1.CompareTo(i2) < 0; + bool smaller2 = i1 == 100; + C c = new() { MyInt = MyInt.From(42), MyShort = MyShort.From(123) }; + + // C2 c = new() // {