-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create special base class for single value value objects. (#10)
* Updated packages. * Added special base class for value objects containing only a single value. * Added primitive value object base class (closes #7).
- Loading branch information
Showing
17 changed files
with
481 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "6.0.200" | ||
"version": "6.0.201" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Fluxera.ValueObject | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Fluxera.Guards; | ||
using Fluxera.Utilities.Extensions; | ||
using JetBrains.Annotations; | ||
|
||
/// <summary> | ||
/// A base class for a value object that only contains a single primitive value. | ||
/// </summary> | ||
/// <remarks> | ||
/// The following types are allowed to be used with this class: | ||
/// Any type that returns <c>true</c>f or <see cref="Type.IsPrimitive" /> and | ||
/// additionally <see cref="Enum" /> values, <see cref="string" />, <see cref="decimal" />, | ||
/// <see cref="DateTime" />, <see cref="DateTimeOffset" />, <see cref="TimeSpan" /> and <see cref="Guid" />. | ||
/// </remarks> | ||
/// <typeparam name="TValueObject">The type of the value object.</typeparam> | ||
/// <typeparam name="TValue">The type of the value.</typeparam> | ||
[PublicAPI] | ||
public abstract class PrimitiveValueObject<TValueObject, TValue> : ValueObject<TValueObject> | ||
where TValueObject : ValueObject<TValueObject> | ||
{ | ||
static PrimitiveValueObject() | ||
{ | ||
Type valueType = typeof(TValue); | ||
bool isPrimitive = valueType.IsPrimitive(true, true); | ||
|
||
Guard.Against.False(isPrimitive, nameof(Value), "The value of a primitive value object must be a primitive, string or enum value."); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the single value of the value object. | ||
/// </summary> | ||
public TValue? Value { get; set; } | ||
|
||
/// <inheritdoc /> | ||
protected sealed override IEnumerable<object?> GetEqualityComponents() | ||
{ | ||
yield return this.Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.