-
Notifications
You must be signed in to change notification settings - Fork 336
Graph Engine TSL Compiler is showing its age. Time to update the TSL Compiler #378
Tavi Truman (TaviTruman)
started this conversation in
General
The Amazing Graph Engine TSL Compiler generates, as part of the DSL-centric Storage API, code to manage "Guid" handling through the GuidAccessor type. This class represents a Trinity type corresponding to the .NET Guid type and provides various methods for interacting with Guid values. It also includes implicit conversion operators between GuidAccessor and Guid. Furthermore, the class overrides the Equals method and supplies the == and != operators for comparing instances.
The TSL-generated code contains the ambiguous == operator as it is the cause of errors and warnings. I have written an extension method to circumnavigate the problem by writing a small extension method set:
/// <summary>
/// Compares the equality of a Trinity GuidAccessor with a .NET Guid or another Trinity GuidAccessor.
/// </summary>
/// <param name="tgeGuidAccessor">The Trinity GuidAccessor being compared. Aligned with owl:Individual of class :GuidAccessor.</param>
/// <param name="dotNetGuid">The .NET Guid or Trinity GuidAccessor to compare. Aligned with owl:unionOf(:Guid, :GuidAccessor).</param>
/// <returns>A boolean value indicating equality. Aligned with xsd:boolean.</returns>
/// <remarks>
/// <para>
/// Ontological Commitment:
/// - owl:equivalentProperty :EqualsEx, :sameAs
/// - rdfs:domain :GuidAccessor
/// - rdfs:range xsd:boolean
/// - skos:definition "Compares the equality of two GUID representations."
/// </para>
/// </remarks>
public static class GuidAccessorExtensions
{
/// <summary>
/// Compares the equality of a Trinity GuidAccessor with an object of type Guid or GuidAccessor.
/// </summary>
/// <param name="tgeGuidAccessor">The Trinity GuidAccessor being compared. Aligned with owl:Individual of class :GuidAccessor.</param>
/// <param name="dotNetGuid">The object to compare, which can be either a .NET Guid or a Trinity GuidAccessor. Aligned with owl:unionOf(:Guid, :GuidAccessor).</param>
/// <returns>A boolean value indicating equality. Aligned with xsd:boolean.</returns>
/// <exception cref="ArgumentException">Thrown when the provided object is neither a .NET Guid nor a Trinity GuidAccessor.</exception>
/// <remarks>
/// <para>
/// Ontological Commitment:
/// - owl:equivalentProperty :EqualsEx, :sameAs
/// - rdfs:domain :GuidAccessor
/// - rdfs:range xsd:boolean
/// - skos:definition "Compares the equality of two different representations of a GUID, one from Trinity and another from .NET, in a type-polymorphic fashion."
/// </para>
/// </remarks>
public static bool EqualsEx(this GuidAccessor tgeGuidAccessor, object dotNetGuid)
{
switch (dotNetGuid)
{
case GuidAccessor guidAccessor:
return tgeGuidAccessor.Value().Equals(guidAccessor.Value());
case Guid guidValue:
return tgeGuidAccessor.Value().Equals(guidValue);
default:
throw new ArgumentException("The provided object is neither a Guid nor a GuidAccessor", nameof(dotNetGuid));
}
}
/// <summary>
/// Compares the equality of a Trinity GuidAccessor with a .NET Guid.
/// </summary>
/// <param name="tgeGuidAccessor">The Trinity GuidAccessor being compared. Aligned with owl:Individual of class :GuidAccessor.</param>
/// <param name="dotNetGuid">The .NET Guid to compare. Aligned with owl:Individual of class :Guid.</param>
/// <returns>A boolean value indicating equality. Aligned with xsd:boolean.</returns>
/// <remarks>
/// <para>
/// Ontological Commitment:
/// - owl:equivalentProperty :EqualsEx, :sameAs
/// - rdfs:domain :GuidAccessor
/// - rdfs:range xsd:boolean
/// - skos:definition "Compares the equality of a GUID from Trinity with a GUID from the .NET ecosystem."
/// </para>
/// </remarks>
public static bool EqualsEx(this GuidAccessor tgeGuidAccessor, Guid dotNetGuid)
{
return tgeGuidAccessor.Value().Equals(dotNetGuid);
}
/// <summary>
/// Converts a Trinity GuidAccessor to a .NET Guid.
/// </summary>
/// <param name="tgeGuidAccessor">The Trinity GuidAccessor to be converted. Aligned with owl:Individual of class :GuidAccessor.</param>
/// <returns>A .NET Guid representation. Aligned with owl:Individual of class :Guid.</returns>
/// <remarks>
/// <para>
/// Ontological Commitment:
/// - owl:equivalentProperty :Value, :hasNETGuidRepresentation
/// - rdfs:domain :GuidAccessor
/// - rdfs:range :Guid
/// - skos:definition "Converts a Trinity GuidAccessor to its corresponding .NET Guid representation."
/// </para>
/// <para>
/// Functional Constraints:
/// - F1: ToByteArray() is assumed to be a pure function. If it has side-effects, those should be isolated.
/// </para>
/// </remarks>
private static Guid Value(this GuidAccessor tgeGuidAccessor)
{
// Assuming ToByteArray() is a pure function. If not, isolate side-effects.
return new Guid(tgeGuidAccessor.ToByteArray());
}
}
}
`
For more than a year now I have been re-writing the Graph Engine TSL compiler in my spare time but with the looming .NET 8 and new C# language enhancement on the horizon more time and energy must be devoted to completing the TSL compiler re-write.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment