Skip to content

Commit

Permalink
Merge pull request #8 from altasoft/feature/IDomainValueInterfaceWith…
Browse files Browse the repository at this point in the history
…TypeAndValue

Added another non generic interface IDomainValue where primitiveType …
  • Loading branch information
GregoryNikolaishvili authored Mar 18, 2024
2 parents a7f2a7f + 76f14b3 commit ebbcd15
Show file tree
Hide file tree
Showing 27 changed files with 148 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Product>Domain Primitives</Product>
<Company>ALTA Software llc.</Company>
<Copyright>Copyright © 2024 ALTA Software llc.</Copyright>
<Version>2.0.4</Version>
<Version>2.1.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/AltaSoft.DomainPrimitives.Generator/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ private static void Process(GeneratorData data, string ctorCode, DomainPrimitive
else
builder.AppendStruct(modifiers, data.ClassName, CreateInheritedInterfaces(data, data.ClassName));

builder.AppendLine("/// <inheritdoc/>")
.Append(" public Type GetUnderlyingPrimitiveType() => typeof(").Append(data.PrimitiveTypeFriendlyName).AppendLine(");");

builder.AppendLine("/// <inheritdoc/>")
.Append(" public object GetUnderlyingPrimitiveValue() => (").Append(data.PrimitiveTypeFriendlyName).AppendLine(")this;").NewLine();

builder.AppendLines(ctorCode);

if (needsMathOperators && isByteOrShort)
Expand Down
23 changes: 21 additions & 2 deletions src/AltaSoft.DomainPrimitives/IDomainValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace AltaSoft.DomainPrimitives;
/// This interface serves as a foundation for encapsulating and validating domain-specific values.
/// </summary>
/// <typeparam name="T">The type of the domain value.</typeparam>
public interface IDomainValue<T> where T : IEquatable<T>, IComparable, IComparable<T>
public interface IDomainValue<T> : IDomainValue
where T : IEquatable<T>, IComparable, IComparable<T>
{
/// <summary>
/// Validates the specified value against domain-specific rules.
Expand All @@ -27,4 +28,22 @@ public interface IDomainValue<T> where T : IEquatable<T>, IComparable, IComparab
/// <param name="value">The domain value to be represented as a string.</param>
/// <returns>A string representation of the domain value.</returns>
static virtual string ToString(T value) => value.ToString() ?? string.Empty;
}
}

/// <summary>
/// Represents an interface for domain values.
/// </summary>
public interface IDomainValue
{
/// <summary>
/// Gets the underlying primitive type of the domain value.
/// </summary>
/// <returns>The underlying primitive type of the domain value.</returns>
Type GetUnderlyingPrimitiveType();

/// <summary>
/// Gets the underlying primitive value of the domain value.
/// </summary>
/// <returns>The underlying primitive value of the domain value.</returns>
object GetUnderlyingPrimitiveValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ namespace AltaSoft.DomainPrimitives;
, IParsable<BoolValue>
, IConvertible
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(bool);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (bool)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly bool _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(byte);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (byte)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly byte _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(char);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (char)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly char _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(DateOnly);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (DateOnly)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly DateOnly _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(DateTimeOffset);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (DateTimeOffset)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly DateTimeOffset _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(DateTime);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (DateTime)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly DateTime _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(decimal);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (decimal)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly decimal _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(double);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (double)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly double _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(float);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (float)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly float _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(Guid);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (Guid)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly Guid _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(short);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (short)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly short _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ namespace AltaSoft.DomainPrimitives;
, IParsable<IntOfIntValue>
, IConvertible
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(int);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (int)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly IntValue _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(int);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (int)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly int _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(int);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (int)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly int _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(long);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (long)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly long _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(sbyte);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (sbyte)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly sbyte _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public partial class StringOfStringValue : IEquatable<StringOfStringValue>
, IParsable<StringOfStringValue>
, IConvertible
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(string);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (string)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly StringValue _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public partial class StringValue : IEquatable<StringValue>
, IParsable<StringValue>
, IConvertible
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(string);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (string)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly string _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public partial class StringValue : IEquatable<StringValue>
, IParsable<StringValue>
, IConvertible
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(string);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (string)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly string _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(TimeOnly);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (TimeOnly)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly TimeOnly _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(TimeSpan);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (TimeSpan)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly TimeSpan _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(ushort);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (ushort)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly ushort _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(uint);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (uint)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly uint _value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ namespace AltaSoft.DomainPrimitives;
, IUtf8SpanFormattable
#endif
{
/// <inheritdoc/>
public Type GetUnderlyingPrimitiveType() => typeof(ulong);
/// <inheritdoc/>
public object GetUnderlyingPrimitiveValue() => (ulong)this;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly ulong _value;

Expand Down

0 comments on commit ebbcd15

Please sign in to comment.