### MyIntVo Creation and Conversion Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v4.8/partial-record-class8Ls5UqsVLU.verified.txt Demonstrates how to create instances of MyIntVo using static factory methods and how to attempt conversions. ```APIDOC ## MyIntVo.From(int value) ### Description Builds an instance of MyIntVo from the provided underlying integer value. ### Method `static MyIntVo From(int value)` ### Parameters #### Path Parameters - **value** (int) - Required - The underlying integer value to use for creating the MyIntVo instance. ### Response #### Success Response (200) - **MyIntVo** - An instance of the MyIntVo value object. ## MyIntVo.TryFrom(int value, out MyIntVo vo) ### Description Tries to build an instance of MyIntVo from the provided underlying integer value. This method is useful when you want to check if the conversion was successful without throwing an exception. ### Method `static bool TryFrom(int value, out MyIntVo vo)` ### Parameters #### Path Parameters - **value** (int) - Required - The underlying integer value to attempt to convert. - **vo** (MyIntVo) - Output - If the conversion is successful, this will contain the created MyIntVo instance. Otherwise, it will be null. ### Response #### Success Response (200) - **bool** - True if the MyIntVo instance was successfully created, false otherwise. ## MyIntVo.TryFrom(int value) ### Description Tries to build an instance of MyIntVo from the provided underlying integer value, returning a `ValueObjectOrError`. ### Method `static ValueObjectOrError TryFrom(int value)` ### Parameters #### Path Parameters - **value** (int) - Required - The underlying integer value to attempt to convert. ### Response #### Success Response (200) - **ValueObjectOrError** - A `ValueObjectOrError` object containing either the successfully created MyIntVo instance or an error if the conversion failed. ``` -------------------------------- ### Guid Value Object TryFrom (with ValueObjectOrError) Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Escaping/snapshots/snap-v4.8/GenerationOfEscapedTypesTests.GenerationOfEscapedTypes_47fe69b8519b4948.verified.txt Attempts to create a Guid value object from an underlying Guid, returning a ValueObjectOrError. This method always succeeds in this example. ```csharp /// /// Tries to build an instance from the provided underlying value. /// If a normalization method is provided, it will be called. /// If validation is provided, and it fails, an error will be returned. /// /// The primitive value. /// A containing either the value object, or an error. public static global::Vogen.ValueObjectOrError TryFrom(global::System.Guid value) { return new global::Vogen.ValueObjectOrError(new escapedTestspublic_partial_classConversions_NoneSystem_Guid(value)); } ``` -------------------------------- ### MyIntVo Construction and Usage Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v8.0/partial-record-structQLrIUxEPAl.verified.txt Demonstrates how to create instances of MyIntVo using the `From` and `TryFrom` methods, and how to access its underlying value. ```APIDOC ## MyIntVo ### Description A value object that wraps an integer. ### Methods #### `From(int value)` Builds an instance from the provided underlying integer value. - **Parameters** - `value` (int) - The underlying integer value. - **Returns** - An instance of `MyIntVo`. #### `TryFrom(int value)` Tries to build an instance from the provided underlying integer value. - **Parameters** - `value` (int) - The primitive integer value. - **Returns** - A `ValueObjectOrError` containing either the value object or an error. #### `TryFrom(int value, out MyIntVo vo)` Tries to build an instance from the provided underlying integer value. - **Parameters** - `value` (int) - The underlying integer value. - `vo` (out MyIntVo) - An instance of the value object if successful. - **Returns** - `true` if the value object can be built, otherwise `false`. #### `Value` Property Gets the underlying `int` value. Throws `ValueObjectValidationException` if the object is not initialized. - **Returns** - The underlying `int` value. #### `IsInitialized()` Checks if the value object has been initialized. - **Returns** - `true` if initialized, `false` otherwise. ### Serialization `MyIntVo` is configured to serialize and deserialize using `ServiceStack.Text`. - **Serialization Function**: `v => v.ToString()` - **Deserialization Function**: `v => MyIntVo.Parse(v)` ### Type Casting Supports explicit casting between `int` and `MyIntVo`. - `explicit operator MyIntVo(int value)` - `explicit operator int(MyIntVo value)` ``` -------------------------------- ### Get Guid Hash Code Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/GenerationPermutations/snapshots/snap-v8.0/18luqBmqNm.verified.txt Calculates the hash code for the Guid value. This method is overridden to ensure consistent hashing. ```csharp return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); } ``` -------------------------------- ### MyIntVo Initialization and Conversion Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v9.0/partial-record67D9OX1YBs.verified.txt Explains how to initialize and convert MyIntVo instances. ```APIDOC ## MyIntVo Initialization and Conversion ### Description Provides methods for creating and validating instances of MyIntVo. ### Methods - **From(int value)**: Builds an instance from the provided underlying integer value. - **TryFrom(int value, out MyIntVo vo)**: Tries to build an instance from the provided underlying integer value. Returns `true` if successful, `false` otherwise. This method may incorporate normalization and validation logic. - **TryFrom(int value)**: Tries to build an instance from the provided underlying integer value. Returns a `ValueObjectOrError` which contains either the successfully created value object or an error. - **IsInitialized()**: Returns `true` if the value object has been initialized, `false` otherwise. This is particularly relevant when validation is enabled. ``` -------------------------------- ### Guid Value Object TryFrom (with output parameter) Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Escaping/snapshots/snap-v4.8/GenerationOfEscapedTypesTests.GenerationOfEscapedTypes_47fe69b8519b4948.verified.txt Attempts to create a Guid value object from an underlying Guid using an output parameter. Always returns true as no validation is performed in this example. ```csharp /// /// Tries to build an instance from the provided underlying type. /// If a normalization method is provided, it will be called. /// If validation is provided, and it fails, false will be returned. /// /// The underlying type. /// An instance of the value object. /// True if the value object can be built, otherwise false. public static bool TryFrom( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif global::System.Guid value, #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.MaybeNullWhen(false)] #endif out escapedTestspublic_partial_classConversions_NoneSystem_Guid vo) { vo = new escapedTestspublic_partial_classConversions_NoneSystem_Guid(value); return true; } ``` -------------------------------- ### TryFrom with System.Half Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/OpenApi/snapshots/snap-v9.0/OpenApiTests.Treats_IParsable_primitives_as_strings_5cd412becf8e1bb9.verified.txt Demonstrates how to create a Vogen Value Object from a System.Half primitive. Includes handling for normalization and validation. ```APIDOC ## TryFrom(System.Half value, out MyVo vo) ### Description Tries to build an instance of a Value Object from the provided underlying System.Half type. If a normalization method is provided, it will be called. If validation is provided and it fails, false will be returned. ### Method Signature ```csharp public static bool TryFrom(global::System.Half value, out MyVo vo) ``` ### Parameters #### Path Parameters - **value** (global::System.Half) - The underlying type. - **vo** (out MyVo) - An instance of the value object. ### Returns - **bool** - True if the value object can be built, otherwise false. ``` ```APIDOC ## TryFrom(System.Half value) ### Description Tries to build an instance of a Value Object from the provided underlying System.Half primitive value. If a normalization method is provided, it will be called. If validation is provided and it fails, an error will be returned. ### Method Signature ```csharp public static global::Vogen.ValueObjectOrError TryFrom(global::System.Half value) ``` ### Parameters #### Path Parameters - **value** (global::System.Half) - The primitive value. ### Returns - **global::Vogen.ValueObjectOrError** - A ValueObjectOrError containing either the value object or an error. ``` -------------------------------- ### Guid.GetHashCode Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/GenerationPermutations/snapshots/snap-v4.8-us/WMVLzBfTuM.verified.txt Gets the hash code for the Guid value object. ```APIDOC ## GetHashCode Guid ### Description Gets the hash code for the Guid value object. ### Method int GetHashCode() ### Response #### Success Response - **return value** (int) - The hash code of the Guid value object. ``` -------------------------------- ### Get Hash Code for Guid Value Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/GenerationPermutations/snapshots/snap-v9.0/Gr0OHLjXmU.verified.txt Computes the hash code for the underlying Guid value. Ensures the value object is initialized before accessing the value. ```csharp public readonly override global::System.Int32 GetHashCode() { return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); ``` -------------------------------- ### MyIntVo Creation and Conversion Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v4.8/partial-recordQ31xUPuiiq.verified.txt Demonstrates how to create instances of MyIntVo using static factory methods and how to handle potential conversion scenarios. ```APIDOC ## MyIntVo.From(int value) ### Description Builds an instance of MyIntVo from the provided underlying integer value. ### Method `public static MyIntVo From(int value)` ### Parameters #### Path Parameters - **value** (int) - Required - The underlying integer value. ### Response #### Success Response (200) - **MyIntVo** - An instance of the MyIntVo value object. ## MyIntVo.TryFrom(int value, out MyIntVo vo) ### Description Tries to build an instance of MyIntVo from the provided underlying integer value. This method is useful when you need to check if the conversion was successful without throwing an exception. ### Method `public static bool TryFrom(int value, out MyIntVo vo)` ### Parameters #### Path Parameters - **value** (int) - Required - The underlying integer value. - **vo** (out MyIntVo) - Required - An output parameter that will contain the created MyIntVo instance if successful. ### Response #### Success Response (200) - **bool** - True if the value object was successfully created, otherwise false. ## MyIntVo.TryFrom(int value) ### Description Tries to build an instance of MyIntVo from the provided underlying integer value, returning a `ValueObjectOrError`. ### Method `public static ValueObjectOrError TryFrom(int value)` ### Parameters #### Path Parameters - **value** (int) - Required - The primitive integer value. ### Response #### Success Response (200) - **ValueObjectOrError** - A `ValueObjectOrError` containing either the created MyIntVo instance or an error. ## MyIntVo.IsInitialized() ### Description Checks if the MyIntVo instance has been initialized. This is particularly relevant when Vogen's validation is enabled. ### Method `public bool IsInitialized()` ### Response #### Success Response (200) - **bool** - True if the value object is initialized, otherwise false. ``` -------------------------------- ### Escaped Test Type Definition Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Escaping/snapshots/snap-v4.8/GenerationOfEscapedTypesTests.GenerationOfEscapedTypes_61fac8bd2a10e8ec.verified.txt An example of a generated C# type definition for testing purposes, featuring attributes for debugging and code generation. This specific example uses a Guid as its underlying type. ```csharp namespace @class { [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(escapedTestspublic_readonly_partial_record_structConversions_NoneSystem_GuidDebugView))] [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: global::System.Guid, Value = { _value }")] ``` -------------------------------- ### MyIntVo Construction Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v8.0/partial-record-classQ31xUPuiiq.verified.txt Demonstrates how to create instances of MyIntVo using static factory methods. ```APIDOC ## MyIntVo.From(int value) ### Description Builds an instance of MyIntVo from the provided underlying integer value. ### Method `static MyIntVo From(int value)` ### Parameters * **value** (int) - The underlying integer value. ### Returns An instance of MyIntVo. ## MyIntVo.TryFrom(int value, out MyIntVo vo) ### Description Tries to build an instance of MyIntVo from the provided underlying integer value. This method also handles normalization and validation if configured. ### Method `static bool TryFrom(int value, out MyIntVo vo)` ### Parameters * **value** (int) - The underlying integer value. * **vo** (out MyIntVo) - An output parameter that will contain the created MyIntVo instance if successful. ### Returns `true` if the MyIntVo instance was successfully created, `false` otherwise. ## MyIntVo.TryFrom(int value) ### Description Tries to build an instance of MyIntVo from the provided underlying integer value, returning a `ValueObjectOrError`. ### Method `static ValueObjectOrError TryFrom(int value)` ### Parameters * **value** (int) - The primitive integer value. ### Returns A `ValueObjectOrError` containing either the successfully created MyIntVo instance or an error. ``` -------------------------------- ### MyIntVo Creation and Conversion Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v9.0/partial-record8Ls5UqsVLU.verified.txt Demonstrates how to create instances of MyIntVo using factory methods and how to attempt conversions. ```APIDOC ## MyIntVo Factory Methods ### Description Provides methods to create `MyIntVo` instances from an underlying `int` value. ### Methods #### `From(int value)` * **Description**: Builds an instance from the provided underlying type. * **Parameters**: * `value` (int) - Required - The underlying integer value. * **Returns**: An instance of `MyIntVo`. #### `TryFrom(int value, out MyIntVo vo)` * **Description**: Tries to build an instance from the provided underlying type. Returns `true` if successful, `false` otherwise. * **Parameters**: * `value` (int) - Required - The underlying integer value. * `vo` (out MyIntVo) - Required - An output parameter to hold the created `MyIntVo` instance. * **Returns**: `true` if the value object can be built, otherwise `false`. #### `TryFrom(int value)` * **Description**: Tries to build an instance from the provided underlying value. Returns a `ValueObjectOrError` containing either the value object or an error. * **Parameters**: * `value` (int) - Required - The primitive integer value. * **Returns**: A `ValueObjectOrError` containing either the `MyIntVo` instance or an error. ``` -------------------------------- ### MyVo.GetHashCode() Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/StaticAbstracts/snapshots/snap-v8.0/0Rjlo8wVsY.verified.txt Gets the hash code for the MyVo object. This is based on the hash code of the underlying Guid value. ```APIDOC ## MyVo.GetHashCode() ### Description Gets the hash code for the MyVo object. This is based on the hash code of the underlying Guid value. ### Method `public readonly override global::System.Int32 GetHashCode()` ### Parameters None ### Request Example None ### Response #### Success Response (200) - **int**: The hash code of the MyVo object. #### Response Example None ``` -------------------------------- ### Escaped Record Class for Guid with Newtonsoft.Json Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Escaping/snapshots/snap-v8.0/GenerationOfEscapedEfCoreConverters.GenerationOfEscapedTypes_76fcc90c4238fccf.verified.txt An example of a generated sealed partial record class for a Guid, demonstrating escaping of type names for compatibility with Newtonsoft.Json. It includes various interfaces for comparison, parsing, and formatting. ```csharp // ------------------------------------------------------------------------------ // // This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ------------------------------------------------------------------------------ // Suppress warnings about [Obsolete] member usage in generated code. #pragma warning disable CS0618 // Suppress warnings for 'Override methods on comparable types'. #pragma warning disable CA1036 // Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators #pragma warning disable MA0097 // Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' // The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. #pragma warning disable CS8669, CS8632 #pragma warning disable CS8604 // Possible null reference argument. // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 // Suppress warnings about CS8767 : Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). #pragma warning disable CS8767 namespace @class { [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] [global::Newtonsoft.Json.JsonConverter(typeof(escapedTestspublic_sealed_partial_record_classConversions_NewtonsoftJsonSystem_GuidNewtonsoftJsonConverter))] [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(escapedTestspublic_sealed_partial_record_classConversions_NewtonsoftJsonSystem_GuidDebugView))] [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: global::System.Guid, Value = { _value }")] public sealed partial record class escapedTestspublic_sealed_partial_record_classConversions_NewtonsoftJsonSystem_Guid : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable, global::System.IParsable, global::System.ISpanParsable, global::System.IFormattable, global::System.ISpanFormattable, global::System.IUtf8SpanFormattable { #if DEBUG private readonly global::System.Diagnostics.StackTrace _stackTrace = null!; #endif #if !VOGEN_NO_VALIDATION private readonly global::System.Boolean _isInitialized; #endif private readonly global::System.Guid _value; /// /// Gets the underlying value if set, otherwise a is thrown. /// public global::System.Guid Value { [global::System.Diagnostics.DebuggerStepThroughAttribute] [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get { EnsureInitialized(); return _value; } ``` -------------------------------- ### MyIntVo Construction and Casting Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v9.0/partial-record-structiaGiO6yFOT.verified.txt Demonstrates how to create instances of MyIntVo using the `From` and `TryFrom` methods, and how to cast between MyIntVo and int. ```APIDOC ## MyIntVo Construction and Casting ### Description This section covers the primary ways to create and interact with `MyIntVo` instances, including static factory methods and explicit type conversions. ### Methods #### `From(int value)` Builds an instance of `MyIntVo` from the provided underlying integer value. - **Parameters** - `value` (int) - The integer value to wrap. - **Returns** - An instance of `MyIntVo`. #### `TryFrom(int value, out MyIntVo vo)` Tries to build an instance of `MyIntVo` from the provided integer value. This method is useful when you want to avoid exceptions and check for success. - **Parameters** - `value` (int) - The integer value to attempt to convert. - `vo` (out MyIntVo) - An output parameter that will contain the `MyIntVo` instance if successful. - **Returns** - `true` if the `MyIntVo` instance was successfully created, `false` otherwise. #### `TryFrom(int value)` Tries to build an instance of `MyIntVo` from the provided integer value, returning a `ValueObjectOrError`. - **Parameters** - `value` (int) - The integer value to attempt to convert. - **Returns** - A `ValueObjectOrError` containing either the `MyIntVo` instance or an error. ### Type Casting #### `explicit operator MyIntVo(int value)` Allows explicit casting of an `int` to a `MyIntVo`. #### `explicit operator int(MyIntVo value)` Allows explicit casting of a `MyIntVo` to its underlying `int` value. ``` -------------------------------- ### MyVo Struct Definition Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/StaticAbstracts/snapshots/snap-v8.0/as81wtsTdJ.verified.txt An example implementation of a Vogen value object for Guid, including debugging and validation attributes. ```csharp [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(MyVoDebugView))] [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: global::System.Guid, Value = { _value }")] // ReSharper disable once UnusedType.Global public partial struct MyVo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable, global::System.IParsable, global::System.ISpanParsable, global::System.IFormattable, global::System.ISpanFormattable, global::System.IUtf8SpanFormattable, IVogen { #if DEBUG private readonly global::System.Diagnostics.StackTrace _stackTrace = null!; #endif #if !VOGEN_NO_VALIDATION private readonly global::System.Boolean _isInitialized; #endif private readonly global::System.Guid _value; /// /// Gets the underlying value if set, otherwise a is thrown. /// public readonly global::System.Guid Value { [global::System.Diagnostics.DebuggerStepThroughAttribute] [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get { EnsureInitialized(); return _value; } } [global::System.Diagnostics.DebuggerStepThroughAttribute] ``` -------------------------------- ### MyIntVo Creation and Conversion Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v9.0/partial-record-structQ31xUPuiiq.verified.txt Demonstrates how to create and convert MyIntVo instances using static factory methods and explicit conversions. ```APIDOC ## MyIntVo Factory Methods and Conversions ### Description Provides methods for creating `MyIntVo` instances from an underlying `int` and for converting between `MyIntVo` and `int`. ### Methods #### `From(int value)` Builds an instance of `MyIntVo` from the provided `int` value. - **Parameters** - `value` (int) - The underlying integer value. - **Returns** - An instance of `MyIntVo`. #### `TryFrom(int value, out MyIntVo vo)` Tries to build an instance of `MyIntVo` from the provided `int` value. This method always returns `true` as there are no inherent validation failures in this basic example. - **Parameters** - `value` (int) - The underlying integer value. - `vo` (out MyIntVo) - An output parameter that will contain the created `MyIntVo` instance if successful. - **Returns** - `true` if the `MyIntVo` instance was successfully created, otherwise `false`. #### `TryFrom(int value)` Tries to build an instance of `MyIntVo` from the provided `int` value, returning a `ValueObjectOrError`. - **Parameters** - `value` (int) - The underlying integer value. - **Returns** - A `ValueObjectOrError` containing either the created `MyIntVo` instance or an error. ### Explicit Conversions #### `MyIntVo(int value)` (Explicit Cast) Allows explicit casting from an `int` to a `MyIntVo`. ```csharp MyIntVo myInt = (MyIntVo)123; ``` #### `int(MyIntVo value)` (Explicit Cast) Allows explicit casting from a `MyIntVo` to an `int`, retrieving its underlying value. ```csharp int underlyingValue = (int)myInt; ``` ### Initialization Check #### `IsInitialized()` Checks if the value object has been properly initialized. In this basic record struct, it always returns `true` unless Vogen's validation is disabled. - **Returns** - `true` if initialized, `false` otherwise. ``` -------------------------------- ### MyIntVo Construction and Serialization Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v9.0/partial-recordCE600pzF1D.verified.txt Demonstrates how to construct MyIntVo instances using `From` and `TryFrom` methods, and how it integrates with ServiceStack.Text for serialization. ```APIDOC ## MyIntVo Value Object ### Description MyIntVo is a value object that wraps an integer. It provides methods for safe construction and integrates with ServiceStack.Text for serialization and deserialization. ### Construction #### `From(int value)` Builds an instance from the provided underlying integer value. - **Parameters** - `value` (int) - The underlying integer value. - **Returns** - An instance of `MyIntVo`. #### `TryFrom(int value, out MyIntVo vo)` Tries to build an instance from the provided underlying integer value. This method is useful when you need to check if the conversion was successful without throwing an exception. - **Parameters** - `value` (int) - The underlying integer value. - `vo` (out MyIntVo) - An output parameter that will contain the created `MyIntVo` instance if successful. - **Returns** - `true` if the value object can be built, otherwise `false`. #### `TryFrom(int value)` Tries to build an instance from the provided underlying integer value, returning a `ValueObjectOrError`. - **Parameters** - `value` (int) - The primitive integer value. - **Returns** - A `global::Vogen.ValueObjectOrError` containing either the value object or an error. ### Serialization ServiceStack.Text is configured to automatically serialize and deserialize `MyIntVo` instances. - **Serialization Function**: `v => v.ToString()` - **Deserialization Function**: `v => MyIntVo.Parse(v)` ### Properties #### `Value` (int) Gets the underlying integer value. If the value object has not been initialized, accessing this property will throw a `global::Vogen.ValueObjectValidationException`. ### Methods #### `IsInitialized()` Checks if the value object has been initialized. - **Returns** - `true` if initialized, `false` otherwise. #### `Equals(MyIntVo other)` Compares this `MyIntVo` instance with another. - **Parameters** - `other` (MyIntVo) - The `MyIntVo` instance to compare with. - **Returns** - `true` if the instances are equal and initialized, `false` otherwise. ``` -------------------------------- ### Custom Guid Type Parse Method Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Escaping/snapshots/snap-v8.0/GenerationOfEscapedEfCoreConverters.GenerationOfEscapedTypes_202d284430690bc3.verified.txt Defines the start of a Parse method for the custom Guid type, intended to parse a ReadOnlySpan. This method would typically throw an exception if parsing fails, unlike TryParse. ```csharp /// /// /// /// ``` -------------------------------- ### TryFormat to Span Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/GenerationPermutations/snapshots/snap-v8.0-fr/Gr0OHLjXmU.verified.txt Attempts to format the Guid value object into a character span. This is an efficient way to get the string representation for use in performance-sensitive scenarios. ```APIDOC ## TryFormat to Span ### Description Attempts to format the Guid value object into a character span. This is an efficient way to get the string representation for use in performance-sensitive scenarios. ### Method `bool System.ISpanFormattable.TryFormat(global::System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("GuidFormat")] global::System.ReadOnlySpan format, global::System.IFormatProvider provider) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **bool** - True if the formatting was successful, false otherwise. - **int** - The number of characters written to the destination span. #### Response Example None ``` -------------------------------- ### MyIntVo Construction and Serialization Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v8.0/partial-recordiaGiO6yFOT.verified.txt Demonstrates how to create and serialize MyIntVo instances. It includes methods for direct creation, safe conversion, and serialization/deserialization configuration. ```APIDOC ## MyIntVo ### Description A value object representing an integer, with built-in support for serialization and validation. ### Methods #### `From(int value)` Builds an instance of `MyIntVo` from the provided underlying integer value. - **Parameters** - `value` (int) - The integer value to encapsulate. - **Returns** - `MyIntVo` - An instance of `MyIntVo`. #### `TryFrom(int value, out MyIntVo vo)` Tries to build an instance of `MyIntVo` from the provided underlying integer value. This method is useful for scenarios where you want to attempt conversion and check for success. - **Parameters** - `value` (int) - The integer value to convert. - `vo` (out MyIntVo) - An output parameter that will contain the created `MyIntVo` instance if successful. - **Returns** - `bool` - `true` if the conversion was successful, `false` otherwise. #### `TryFrom(int value)` Tries to build an instance of `MyIntVo` from the provided underlying integer value, returning a `ValueObjectOrError`. - **Parameters** - `value` (int) - The integer value to convert. - **Returns** - `ValueObjectOrError` - A `ValueObjectOrError` containing either the created `MyIntVo` instance or an error. #### `IsInitialized()` Checks if the value object has been initialized. This is relevant when validation is enabled. - **Returns** - `bool` - `true` if initialized, `false` otherwise. ### Serialization Configuration ServiceStack.Text.JsConfig is configured to handle serialization and deserialization of `MyIntVo`: - `JsConfig.DeSerializeFn = v => MyIntVo.Parse(v);` - `JsConfig.SerializeFn = v => v.ToString();` ### Properties #### `Value` (int) Gets the underlying integer value. If the value object has not been initialized (and validation is enabled), accessing this property will throw a `ValueObjectValidationException`. - **Getter** - Returns the underlying `int` value. - **Initializer** - Sets the underlying `int` value. ``` -------------------------------- ### Value Object TryFrom Method (Out Parameter) Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Casting/snapshots/snap-v9.0/CastingGenerationTests.Can_specify_casting_at_the_global_config_level_44b1b8e5ec45f12a.verified.txt Tries to create a value object instance from a Guid. Always returns true as no validation is performed in this example. ```csharp /// /// Tries to build an instance from the provided underlying type. /// If a normalization method is provided, it will be called. /// If validation is provided, and it fails, false will be returned. /// /// The underlying type. /// An instance of the value object. /// True if the value object can be built, otherwise false. public static bool TryFrom( #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif global::System.Guid value, #if NETCOREAPP3_0_OR_GREATER [global::System.Diagnostics.CodeAnalysis.MaybeNullWhen(false)] #endif out _casting_public_partial_record_structExplicitImplicitSystem_Guid vo) { vo = new _casting_public_partial_record_structExplicitImplicitSystem_Guid(value); return true; } ``` -------------------------------- ### MyVo.From Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/StaticAbstracts/snapshots/snap-v8.0/lPx7tKaO9H.verified.txt Builds an instance of MyVo from the provided underlying System.Guid value. ```APIDOC ## MyVo.From ### Description Builds an instance of MyVo from the provided underlying System.Guid value. ### Method `public static MyVo From(global::System.Guid value)` ### Parameters #### Path Parameters - **value** (global::System.Guid) - The underlying type to create the MyVo instance from. ### Returns An instance of MyVo. ``` -------------------------------- ### MyIntVo Construction and Conversion Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v8.0/readonly-partial-record-structIKki7umr9M.verified.txt Demonstrates how to create and convert MyIntVo instances using static factory methods and explicit conversions. ```APIDOC ## MyIntVo Construction and Conversion This section details the methods available for creating and converting `MyIntVo` instances. ### Static Factory Methods - **`From(int value)`**: Builds an instance from the provided underlying integer value. - **`TryFrom(int value, out MyIntVo vo)`**: Tries to build an instance from the provided underlying integer value. Returns `true` if successful, `false` otherwise. - **`TryFrom(int value)`**: Tries to build an instance from the provided underlying integer value. Returns a `ValueObjectOrError` containing either the value object or an error. ### Explicit Conversions - **`explicit operator MyIntVo(int value)`**: Converts an integer to a `MyIntVo` instance. - **`explicit operator int(MyIntVo value)`**: Converts a `MyIntVo` instance to its underlying integer value. ``` -------------------------------- ### Setup .NET Console Logger Source: https://github.com/stevedunn/vogen/blob/main/docs/site/Writerside/topics/tutorials/Working-with-logging-frameworks.md Configure the default .NET logging framework to output logs to the console. Ensure you have the necessary NuGet packages installed. ```csharp using Microsoft.Extensions.Logging; using var loggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); }); ILogger logger = loggerFactory.CreateLogger(); ``` -------------------------------- ### MyIntVo Construction and Serialization Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v9.0/sealed-partial-recordQ31xUPuiiq.verified.txt Demonstrates how to create instances of MyIntVo using the `From` and `TryFrom` methods, and how it integrates with ServiceStack.Text for serialization and deserialization. ```APIDOC ## MyIntVo Value Object This document outlines the `MyIntVo` record, a sealed partial record class designed to represent an integer value object. ### Construction Instances of `MyIntVo` can be created using the following static methods: - **`From(int value)`**: Builds an instance from the provided underlying integer value. - **`TryFrom(int value, out MyIntVo vo)`**: Tries to build an instance from the provided underlying integer value. Returns `true` if successful, `false` otherwise. - **`TryFrom(int value)`**: Tries to build an instance from the provided underlying integer value. Returns a `ValueObjectOrError` containing either the value object or an error. ### Serialization `MyIntVo` integrates with `ServiceStack.Text` for serialization and deserialization: - **Serialization**: `JsConfig.SerializeFn` is set to `v => v.ToString()`, meaning instances will be serialized to their string representation. - **Deserialization**: `JsConfig.DeSerializeFn` is set to `v => MyIntVo.Parse(v)`, allowing instances to be deserialized from a string. ### Initialization Check - **`IsInitialized()`**: Returns `true` if the value object has been initialized, `false` otherwise. This method's behavior is conditional on the `VOGEN_NO_VALIDATION` preprocessor directive. ### Internal Deserialization - **`__Deserialize(int value)`**: An internal method used for deserializing the value object from its primitive type. This method is intended for internal use only. ``` -------------------------------- ### Generated Value Object Attributes Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Casting/snapshots/snap-v9.0/CastingGenerationTests.Can_specify_casting_at_the_global_config_level_53f8b5b771e17501.verified.txt Defines a generated value object with various attributes for JSON conversion, type conversion, debugging, and display. This example shows a `Guid` based value object. ```csharp [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] [global::System.Text.Json.Serialization.JsonConverter(typeof(_casting_public_partial_record_classNoneExplicitSystem_GuidSystemTextJsonConverter))] [global::System.ComponentModel.TypeConverter(typeof(_casting_public_partial_record_classNoneExplicitSystem_GuidTypeConverter))] [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(_casting_public_partial_record_classNoneExplicitSystem_GuidDebugView))] [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: global::System.Guid, Value = { _value }")] public partial record class _casting_public_partial_record_classNoneExplicitSystem_Guid : global::System.IEquatable<_casting_public_partial_record_classNoneExplicitSystem_Guid>, global::System.IEquatable, global::System.IComparable<_casting_public_partial_record_classNoneExplicitSystem_Guid>, global::System.IComparable, global::System.IParsable<_casting_public_partial_record_classNoneExplicitSystem_Guid>, global::System.ISpanParsable<_casting_public_partial_record_classNoneExplicitSystem_Guid>, global::System.IFormattable, global::System.ISpanFormattable, global::System.IUtf8SpanFormattable ``` -------------------------------- ### MyVo Struct Implementation Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/StaticAbstracts/snapshots/snap-v8.0/ARGteONefa.verified.txt An example implementation of a Vogen value object named 'MyVo' using a Guid as the primitive type. It implements various interfaces for comparison, parsing, and formatting, and includes debug view and display attributes. ```csharp [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(MyVoDebugView))] [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: global::System.Guid, Value = { _value }")] // ReSharper disable once UnusedType.Global public partial struct MyVo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable, global::System.IParsable, global::System.ISpanParsable, global::System.IFormattable, global::System.ISpanFormattable, global::System.IUtf8SpanFormattable, IVogen { #if DEBUG private readonly global::System.Diagnostics.StackTrace _stackTrace = null!; #endif #if !VOGEN_NO_VALIDATION private readonly global::System.Boolean _isInitialized; #endif private readonly global::System.Guid _value; /// /// Gets the underlying value if set, otherwise a is thrown. /// public readonly global::System.Guid Value { [global::System.Diagnostics.DebuggerStepThroughAttribute] ``` -------------------------------- ### TryFrom (Guid value, out MyVo vo) Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/OpenApi/snapshots/snap-v9.0/OpenApiTests.Treats_IParsable_primitives_as_strings_02b3c4469da8bcf3.verified.txt Tries to build a MyVo instance from a Guid. Returns true if successful, false otherwise. ```APIDOC ## TryFrom (Guid value, out MyVo vo) ### Description Tries to build a MyVo instance from the provided underlying Guid value. If a normalization method is provided, it will be called. If validation is provided and it fails, false will be returned. ### Method static bool ### Parameters #### Path Parameters - **value** (Guid) - The underlying type. - **vo** (out MyVo) - An instance of the value object. ### Returns - **bool** - True if the value object can be built, otherwise false. ``` -------------------------------- ### MyIntVo Creation and Conversion Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v4.8/readonly-partial-record-structsThydxQv3t.verified.txt Demonstrates how to create and convert MyIntVo instances using static factory methods and explicit casting. ```APIDOC ## MyIntVo Factory Methods and Casting ### Description This section covers the primary ways to create and interact with `MyIntVo` instances, including static factory methods and explicit type conversions. ### Methods #### `MyIntVo.From(int value)` * **Description**: Builds an instance of `MyIntVo` from the provided underlying integer value. * **Parameters**: * `value` (int) - The integer value to use for the new `MyIntVo` instance. * **Returns**: A new `MyIntVo` instance. #### `MyIntVo.TryFrom(int value, out MyIntVo vo)` * **Description**: Attempts to build an instance of `MyIntVo` from the provided integer value. This method is useful when you need to check for success without exceptions. * **Parameters**: * `value` (int) - The integer value to attempt to convert. * `vo` (out MyIntVo) - If the conversion is successful, this will contain the created `MyIntVo` instance. * **Returns**: `true` if the `MyIntVo` was successfully created, `false` otherwise. #### `MyIntVo.TryFrom(int value)` * **Description**: Attempts to build an instance of `MyIntVo` from the provided integer value, returning a `ValueObjectOrError`. * **Parameters**: * `value` (int) - The integer value to attempt to convert. * **Returns**: A `ValueObjectOrError` which contains either the successfully created `MyIntVo` or an error. #### Explicit Casts * **`explicit operator MyIntVo(int value)`**: * **Description**: Allows explicit casting of an `int` to a `MyIntVo`. * **Usage**: `MyIntVo myVo = (MyIntVo)123;` * **`explicit operator int(MyIntVo value)`**: * **Description**: Allows explicit casting of a `MyIntVo` back to its underlying `int` value. * **Usage**: `int intValue = (int)myVo;` ### Example ```csharp // Creating an instance using From MyIntVo vo1 = MyIntVo.From(100); // Creating an instance using explicit cast MyIntVo vo2 = (MyIntVo)200; // Converting back to int using explicit cast int value1 = (int)vo1; // Using TryFrom to safely attempt creation if (MyIntVo.TryFrom(300, out MyIntVo vo3)) { // Successfully created vo3 } // Using TryFrom with ValueObjectOrError var result = MyIntVo.TryFrom(400); if (result.IsSuccess) { MyIntVo vo4 = result.Value; } ``` ``` -------------------------------- ### Generated EF Core Value Converter for Guid Type Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/Escaping/snapshots/snap-v8.0/GenerationOfEscapedEfCoreConverters.GenerationOfEscapedTypes_9a0e1c590d3ebd3b.verified.txt This is an example of a generated EF Core `ValueConverter` for a Vogen type that wraps a `System.Guid`. It handles the conversion between the Vogen type and the underlying `System.Guid` for database storage and retrieval. ```csharp namespace @class; public partial class EfCoreConverters { public class escapedTestspublic_partial_structConversions_NoneSystem_GuidEfCoreValueConverter : global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<@class.escapedTestspublic_partial_structConversions_NoneSystem_Guid, System.Guid> { public escapedTestspublic_partial_structConversions_NoneSystem_GuidEfCoreValueConverter() : this(null) { } public escapedTestspublic_partial_structConversions_NoneSystem_GuidEfCoreValueConverter(global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) : base( vo => vo.Value, value => Deserialize(value), mappingHints ) { } static @class.escapedTestspublic_partial_structConversions_NoneSystem_Guid Deserialize(System.Guid value) => UnsafeDeserialize(default, value); ``` -------------------------------- ### MyIntVo Factory Methods Source: https://github.com/stevedunn/vogen/blob/main/tests/SnapshotTests/ConversionPermutations/snapshots/snap-v9.0/partial-record-structQLrIUxEPAl.verified.txt Demonstrates how to create instances of MyIntVo using factory methods. ```APIDOC ## MyIntVo Factory Methods ### Description Provides static methods for creating and validating instances of the MyIntVo value object. ### Methods - **From(int value)**: Builds an instance from the provided underlying integer value. - **TryFrom(int value, out MyIntVo vo)**: Tries to build an instance from the provided integer. Returns `true` if successful, `false` otherwise. - **TryFrom(int value)**: Tries to build an instance from the provided integer. Returns a `ValueObjectOrError` containing either the value object or an error. ```