Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
34c3805
add requirements.md
Oct 25, 2025
c14b9d7
add requirements
Oct 25, 2025
b3e61b2
update requirements.md
Oct 25, 2025
3fcc9a5
update requirements.md
Oct 26, 2025
eecb8c6
update test lib, add test app
Oct 26, 2025
c6af13c
migrate to slnx
Oct 26, 2025
218d7e0
wip
Oct 29, 2025
9efa8a7
add lyra
Oct 29, 2025
13ff8b4
update README.md
Oct 29, 2025
bd722cc
Merge branch 'refs/heads/lyra' into unions2
Oct 29, 2025
54efcc1
update lyra version
Oct 29, 2025
18acb18
add polyfills generator
Dec 7, 2025
1cd62df
implement janus
Dec 9, 2025
f1acb48
implement lyra
Dec 9, 2025
22dea92
fixed nuget setup
Dec 9, 2025
b9aeab4
wip
Dec 9, 2025
5960017
remove unions generator
Dec 9, 2025
deba3da
increment ikvm msbuild version
Dec 9, 2025
02bc097
add solution name
Dec 9, 2025
2299568
remove globals.json
Dec 9, 2025
065233f
project changes
Dec 9, 2025
27318a5
add Equa
Dec 9, 2025
6675627
utilize janus
Dec 9, 2025
f52ac7c
utilize lyra
Dec 9, 2025
d085ba0
fix all warnings
Dec 20, 2025
3f33de3
Revert "fix all warnings"
Dec 20, 2025
87a39d4
add utilitygenerators.dev
Dec 21, 2025
6f80712
emit janus package on debug build to dev
Dec 21, 2025
ba3b0ac
use janus directly
Dec 21, 2025
f751f58
fix dsl generator
Dec 21, 2025
49d85fa
allow user provided equality operators
Dec 21, 2025
4d1a761
Merge branch 'release' into unions2
SleepWellPupper Dec 21, 2025
386cf83
update README.md
Dec 21, 2025
9b887c0
throw generic ArgumentException if validation does not
Dec 21, 2025
8d8805e
add named factory methods for overload ambiguity resolution
Dec 21, 2025
b31ece3
make generic type parameter check netstandard2 compliant
Dec 21, 2025
4ba1aec
improve space formatting
Dec 21, 2025
2f4a187
Merge remote-tracking branch 'origin/unions2' into unions2
Dec 21, 2025
e9546e9
Merge branch 'release' into unions2
Dec 21, 2025
ad09438
update README.md
Dec 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Janus.Analyzers/Components/ConstructorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public void AppendTo(CSharpSourceBuilder builder, CancellationToken cancellation
{
var isValid = true;
Validate(value, throwIfInvalid: true, ref isValid);
if(!isValid)
{
throw new {{typeof(ArgumentException)}}($"{nameof(value)} was invalid.", nameof(value));
}
}

{{Create(variant, static (v, b, ct) =>
Expand Down
64 changes: 64 additions & 0 deletions Janus.Analyzers/Components/FactoriesComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,28 @@ public static bool TryCreate(
{{variant.Type.NullableName}} value)
=> new {{new UnionTypeNameComponent(m)}}(value, validate: true);

{{Summary(m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();

b.Append($"Creates an instance of {Cref(m.DocsCommentId)}.");
})}}
{{Param("value", m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();

b.Append($"The value to create an instance of {Cref(m.DocsCommentId)} from.");
})}}
{{Returns(m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();

b.Append($"The new instance of {Cref(m.DocsCommentId)}.");
})}}
public static {{new UnionTypeNameComponent(m)}} CreateFrom{{variant.Name}}(
{{variant.Type.NullableName}} value)
=> new {{new UnionTypeNameComponent(m)}}(value, validate: true);

{{Summary(m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -238,6 +260,48 @@ public static bool TryCreate(

return isValid;
}

{{Summary(m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();

b.Append($"Attempts to create an instance of {Cref(m.DocsCommentId)}.");
})}}
{{Param("value", m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();

b.Append($"The value to create an instance of {Cref(m.DocsCommentId)} from.");
})}}
{{Param("union", m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();

b.Append(
$"""
The instance of {Cref(m.DocsCommentId)} if one could be created; otherwise,
{(m.TypeKind is UnionTypeKind.Class ? Langword("null") : Langword("default"))}.
""");
})}}
{{Returns(m, static (m, b, ct) =>
{
ct.ThrowIfCancellationRequested();

b.Append($"{Langword("true")} if an instance of {Cref(m.DocsCommentId)} could be created; otherwise, {Langword("false")}.");
})}}
public static bool TryCreateFrom{{variant.Name}}(
{{variant.Type.NullableName}} value,
[{{typeof(NotNullWhenAttribute)}}(true)]
out {{new UnionTypeNameComponent(m, RenderNullable: true)}} union)
{
var isValid = true;
Validate(value, throwIfInvalid: false, ref isValid);
union = isValid
? new {{new UnionTypeNameComponent(m)}}(value, validate: false)
: default;

return isValid;
}
"""
);
}
Expand Down
2 changes: 1 addition & 1 deletion Janus.Analyzers/Components/ToStringComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override string ToString()

b.Append(
$$"""
{{p}}{(typeof({{p}}).IsGenericTypeParameter ? string.Empty : $":{typeof({{p}})}" )}
{{p}}{(typeof({{p}}) is { IsGenericParameter: true, DeclaringMethod: null } ? string.Empty : $":{typeof({{p}})}" )}
"""
);
}, separator: ", ")}>");
Expand Down
2 changes: 1 addition & 1 deletion Janus.Analyzers/UnionTypeSettingsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ sealed partial class UnionTypeSettingsAttribute : global::System.Attribute
/// Defines how to generate an implementation for <see cref="Object.ToString"/>.
/// </summary>
public ToStringSetting ToStringSetting { get; set; }

/// <summary>
/// Indicates how to generate equality operators.
/// By default, equality operators will only be emitted for value types, to preserve
/// reference equality for comparing reference union types via <c>==</c> or <c>!=</c>.
/// </summary>
public EqualityOperatorsSetting EqualityOperatorsSetting { get; set; }


/// <summary>
/// Gets or sets a value indicating whether to make the union type JSON serializable.
/// </summary>
Expand Down
Loading
Loading