Skip to content

Commit

Permalink
fix: review feedback 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bmazzarol committed Jan 8, 2025
1 parent cae2afb commit fcf8530
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 28 deletions.
5 changes: 2 additions & 3 deletions Tuxedo.SourceGenerator/Extensions/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ is true
public static bool HasInterface(this ITypeSymbol? symbol, string interfaceName)
{
return symbol?.AllInterfaces.Any(i =>
i.ToDisplayString().Equals(interfaceName, StringComparison.Ordinal)
)
is true;
i.ToDisplayString().Equals(interfaceName, StringComparison.Ordinal)
) ?? false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static string RenderMultiRefinedType(RefinedTypeDetails model)
/// Standard deconstruction to the underlying values
/// </summary>
/// <param name="value">raw {{model.RawType.EscapeXml()}}</param>
/// <param name="altValue">alternative {{model.AlternativeType.EscapeXml()}}</param>
/// <param name="altValue">The alternative {{model.AlternativeType.EscapeXml()}} produced when the refinement predicate is satisfied</param>
public void Deconstruct(out {{model.RawType}} value, out {{model.AlternativeType}} altValue)
{
value = Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ public override string ToString()
{
return Value.ToString() ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying bool
/// </summary>
public string ToString(IFormatProvider? provider)
{
return ((IConvertible)Value).ToString(provider) ?? string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ public override string ToString()
{
return Value.ToString() ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying bool
/// </summary>
public string ToString(IFormatProvider? provider)
{
return ((IConvertible)Value).ToString(provider) ?? string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ public override string ToString()
{
return Value.ToString() ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying bool
/// </summary>
public string ToString(IFormatProvider? provider)
{
return ((IConvertible)Value).ToString(provider) ?? string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ public override string ToString()
{
return Value.ToString() ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying bool
/// </summary>
public string ToString(IFormatProvider? provider)
{
return ((IConvertible)Value).ToString(provider) ?? string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace <global namespace>;
/// A refined char based on the Test.WhiteSpace refinement predicate
/// </summary>
[RefinedType]
internal readonly partial struct WhiteSpaceChar : IEquatable<WhiteSpaceChar>
internal readonly partial struct WhiteSpaceChar : IEquatable<WhiteSpaceChar>, IFormattable
{
private readonly char? _value;

Expand Down Expand Up @@ -120,4 +120,20 @@ public override string ToString()
{
return Value.ToString() ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying char
/// </summary>
public string ToString(IFormatProvider? provider)
{
return ((IConvertible)Value).ToString(provider) ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying char
/// </summary>
public string ToString(string? format, IFormatProvider? formatProvider)
{
return ((IFormattable)Value).ToString(format, formatProvider) ?? string.Empty;
}
}
30 changes: 19 additions & 11 deletions Tuxedo.Tests/DateOnlyExample.Case3#DateOnlyString.g.verified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace <global namespace>;

/// <summary>
/// A refined string based on the Test.DateOnly refinement predicate which produces an alternative DateOnly value
/// A refined string based on the Test.DateOnly refinement predicate which produces an alternative System.DateOnly value
/// </summary>
[RefinedType]
public readonly partial struct DateOnlyString : IEquatable<DateOnlyString>
Expand All @@ -31,24 +31,24 @@ public static implicit operator string(DateOnlyString @this)
return @this.Value;
}

private readonly DateOnly? _altValue;
private readonly System.DateOnly? _altValue;

/// <summary>
/// The underlying DateOnly
/// The underlying System.DateOnly
/// </summary>
public DateOnly AltValue => _altValue ?? throw new InvalidOperationException("Do not use the default value, please use the Parse and TryParse methods to construct a DateOnlyString");
public System.DateOnly AltValue => _altValue ?? throw new InvalidOperationException("Do not use the default value, please use the Parse and TryParse methods to construct a DateOnlyString");

/// <summary>
/// Implicit conversion from the DateOnlyString to a DateOnly
/// Implicit conversion from the DateOnlyString to a System.DateOnly
/// </summary>
/// <param name="this">the DateOnlyString</param>
/// <returns>underlying DateOnly</returns>
public static implicit operator DateOnly(DateOnlyString @this)
/// <returns>underlying System.DateOnly</returns>
public static implicit operator System.DateOnly(DateOnlyString @this)
{
return @this.AltValue;
}

private DateOnlyString(string value, DateOnly altValue)
private DateOnlyString(string value, System.DateOnly altValue)
{
_value = value;
_altValue = altValue;
Expand Down Expand Up @@ -77,7 +77,7 @@ public static DateOnlyString Parse(string value)
}

/// <summary>
/// Try and refine the string against the Test.DateOnly refinement producing a DateOnly
/// Try and refine the string against the Test.DateOnly refinement producing a System.DateOnly
/// </summary>
/// <param name="value">raw string</param>
/// <param name="refined">refined DateOnlyString when true</param>
Expand Down Expand Up @@ -139,12 +139,20 @@ public override string ToString()
return Value.ToString() ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying string
/// </summary>
public string ToString(IFormatProvider? provider)
{
return ((IConvertible)Value).ToString(provider) ?? string.Empty;
}

/// <summary>
/// Standard deconstruction to the underlying values
/// </summary>
/// <param name="value">raw string</param>
/// <param name="altValue">alternative DateOnly</param>
public void Deconstruct(out string value, out DateOnly altValue)
/// <param name="altValue">The alternative System.DateOnly produced when the refinement predicate is satisfied</param>
public void Deconstruct(out string value, out System.DateOnly altValue)
{
value = Value;
altValue = AltValue;
Expand Down
8 changes: 7 additions & 1 deletion Tuxedo.Tests/Extensions/GeneratorDriverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ internal static GeneratorDriver BuildDriver(this string? source)
{
var compilation = CSharpCompilation.Create(
"name",
source != null ? [CSharpSyntaxTree.ParseText(source)] : []
source != null ? [CSharpSyntaxTree.ParseText(source)] : [],
[
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(RefinementAttribute).Assembly.Location),
],
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
);
var generator = new RefinementSourceGenerator();
var driver = CSharpGeneratorDriver.Create(generator);
Expand All @@ -34,6 +39,7 @@ internal static Task VerifyRefinement(
)
{
var driver = $$"""
using System;
using Tuxedo;
internal static class Test
Expand Down
30 changes: 19 additions & 11 deletions Tuxedo.Tests/GuidStringTests.Case3#GuidString.g.verified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace <global namespace>;

/// <summary>
/// A refined string based on the Test.Guid refinement predicate which produces an alternative Guid value
/// A refined string based on the Test.Guid refinement predicate which produces an alternative System.Guid value
/// </summary>
[RefinedType]
public readonly partial struct GuidString : IEquatable<GuidString>
Expand All @@ -31,24 +31,24 @@ public static implicit operator string(GuidString @this)
return @this.Value;
}

private readonly Guid? _altValue;
private readonly System.Guid? _altValue;

/// <summary>
/// The underlying Guid
/// The underlying System.Guid
/// </summary>
public Guid AltValue => _altValue ?? throw new InvalidOperationException("Do not use the default value, please use the Parse and TryParse methods to construct a GuidString");
public System.Guid AltValue => _altValue ?? throw new InvalidOperationException("Do not use the default value, please use the Parse and TryParse methods to construct a GuidString");

/// <summary>
/// Implicit conversion from the GuidString to a Guid
/// Implicit conversion from the GuidString to a System.Guid
/// </summary>
/// <param name="this">the GuidString</param>
/// <returns>underlying Guid</returns>
public static implicit operator Guid(GuidString @this)
/// <returns>underlying System.Guid</returns>
public static implicit operator System.Guid(GuidString @this)
{
return @this.AltValue;
}

private GuidString(string value, Guid altValue)
private GuidString(string value, System.Guid altValue)
{
_value = value;
_altValue = altValue;
Expand Down Expand Up @@ -77,7 +77,7 @@ public static GuidString Parse(string value)
}

/// <summary>
/// Try and refine the string against the Test.Guid refinement producing a Guid
/// Try and refine the string against the Test.Guid refinement producing a System.Guid
/// </summary>
/// <param name="value">raw string</param>
/// <param name="refined">refined GuidString when true</param>
Expand Down Expand Up @@ -139,12 +139,20 @@ public override string ToString()
return Value.ToString() ?? string.Empty;
}

/// <summary>
/// Returns the string representation of the underlying string
/// </summary>
public string ToString(IFormatProvider? provider)
{
return ((IConvertible)Value).ToString(provider) ?? string.Empty;
}

/// <summary>
/// Standard deconstruction to the underlying values
/// </summary>
/// <param name="value">raw string</param>
/// <param name="altValue">alternative Guid</param>
public void Deconstruct(out string value, out Guid altValue)
/// <param name="altValue">The alternative System.Guid produced when the refinement predicate is satisfied</param>
public void Deconstruct(out string value, out System.Guid altValue)
{
value = Value;
altValue = AltValue;
Expand Down
Loading

0 comments on commit fcf8530

Please sign in to comment.