Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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>Choice generator</Product>
<Company>ALTA Software llc.</Company>
<Copyright>Copyright © 2024 ALTA Software llc.</Copyright>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
14 changes: 9 additions & 5 deletions src/AltaSoft.Choice.Generator/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ private static SourceCodeBuilder Process(INamedTypeSymbol typeSymbol, List<IProp
if (p.Summary is not null)
sb.AppendSummary(p.Summary);

sb.AppendLine("[DisallowNull]");

var isDateOnly = p.IsDateOnly();
if (isDateOnly)
{
sb.AppendLine("[XmlIgnore]");
}
else
{
sb.AppendLine("[DisallowNull]");
sb.Append("[XmlElement(\"").Append(p.XmlNameValue).AppendLine("\")]");
}

Expand Down Expand Up @@ -234,10 +233,15 @@ private static bool ProcessImplicitOperators(SourceCodeBuilder sb, string typeNa
{
sb.AppendSummary($"Implicitly converts an <see cref=\"{property.TypeName}\"/> to an <see cref=\"{typeName}\"/>.");
sb.AppendParamDescription("value", $"The <see cref=\"{property.TypeName}\"/> to convert.");
sb.AppendBlock("returns", $"<see cref=\"{typeName}\"/> instance representing the code.");
sb.AppendBlock("returns", $"<see cref=\"{typeName}\"/> instance representing the code.").NewLine();
sb.AppendLine("[return: NotNullIfNotNull(parameterName: nameof(value))]");

sb.Append("public static implicit operator ").Append(typeName).Append("? (")
.Append(property.TypeName).AppendLine("? value) ")
.OpenBracket()
.Append("return value is null ? null : CreateAs").Append(property.Name).Append("(value").AppendIf(property.TypeSymbol.IsValueType, ".Value").AppendLine(");")
.CloseBracket();

sb.Append("public static implicit operator ").Append(typeName).Append("(")
.Append(property.TypeName).Append(" value) => CreateAs").Append(property.Name).AppendLine("(value);");
sb.NewLine();
}

Expand Down
6 changes: 4 additions & 2 deletions src/AltaSoft.Choice.Generator/Extensions/CompilationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static string GetClassNameWithArguments(this INamedTypeSymbol? type)

return builder.ToString();
}

#pragma warning disable S1643
public static string GetFullName(this ITypeSymbol type)
{
var ns = type.ContainingNamespace?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.OmittedAsContaining))!;
Expand Down Expand Up @@ -175,12 +175,14 @@ public static string GetFullName(this ITypeSymbol type)
for (var i = 0; i < typeParameters.Length; ++i)
{
var typeParamName = typeParameters[i].ToString();

friendlyName += i == 0 ? typeParamName : "," + typeParamName;

}
friendlyName += ">";
return ns + '.' + friendlyName;
}

#pragma warning restore S1643
/// <summary>
/// Determines whether the specified type symbol is a Nullable&lt;T&gt; value type and, if so, provides the underlying value type symbol.
/// </summary>
Expand Down
56 changes: 0 additions & 56 deletions src/AltaSoft.Choice.Generator/Extensions/RoslynExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,6 @@ namespace AltaSoft.Choice.Generator.Extensions;
/// </summary>
internal static class RoslynExt
{
///// <summary>
///// Gets the location of the attribute data within the source code.
///// </summary>
///// <param name="self">The attribute data to retrieve the location for.</param>
///// <returns>The location of the attribute data in the source code, or null if not found.</returns>
//public static Location? GetAttributeLocation(this AttributeData self)
//{
// var syntaxReference = self.ApplicationSyntaxReference;

// var syntax = (AttributeSyntax?)syntaxReference?.GetSyntax();

// return syntax?.GetLocation();
//}

///// <summary>
///// Checks if the symbol has a default constructor (parameterless constructor) defined and retrieves its location.
///// </summary>
///// <param name="self">The symbol to check for a default constructor.</param>
///// <param name="location">When this method returns, contains the location of the default constructor, if found; otherwise, null.</param>
///// <returns>True if a default constructor is found; otherwise, false.</returns>
//public static bool HasDefaultConstructor(this ISymbol? self, out Location? location)
//{
// var constructors = self.GetConstructorsFromSyntaxTree();

// var ctor = constructors?.Find(x => x.ParameterList.Parameters.Count == 0);
// location = ctor?.GetLocation();
// return ctor is not null;
//}

///// <summary>
///// Retrieves a list of constructor declarations associated with the symbol from the syntax tree.
///// </summary>
///// <param name="self">The symbol for which to retrieve constructor declarations.</param>
///// <returns>A list of constructor declarations or null if none are found.</returns>
//public static List<ConstructorDeclarationSyntax>? GetConstructorsFromSyntaxTree(this ISymbol? self)
//{
// var declaringSyntaxReferences = self?.DeclaringSyntaxReferences;

// if (self is null || declaringSyntaxReferences is null or { Length: 0 })
// return null;

// List<ConstructorDeclarationSyntax>? result = null;

// foreach (var syntax in declaringSyntaxReferences)
// {
// if (syntax.GetSyntax() is TypeDeclarationSyntax classDeclaration && string.Equals(classDeclaration.GetClassFullName(), self.ToString(), System.StringComparison.Ordinal))
// {
// var constructors = classDeclaration.Members.OfType<ConstructorDeclarationSyntax>();

// result ??= [];
// result.AddRange(constructors);
// }
// }
// return result;
//}

/// <summary>
/// Gets the namespace of the specified type declaration syntax.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions src/AltaSoft.Choice.Generator/Helpers/SourceCodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ public SourceCodeBuilder AppendLines(IEnumerable<string> lines)
{
_sb.AppendLine();
}
else
if (line[0] == '#')
else if (line[0] == '#')
{
_sb.AppendLine(line);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ public void Switch(
/// <returns>
/// <see cref="Authorisation1Choice"/> instance representing the code.
/// </returns>
public static implicit operator Authorisation1Choice(TestNamespace.OtherNamespace.Authorisation1Code value) => CreateAsCode(value);

[return: NotNullIfNotNull(parameterName: nameof(value))]
public static implicit operator Authorisation1Choice? (TestNamespace.OtherNamespace.Authorisation1Code? value)
{
return value is null ? null : CreateAsCode(value.Value);
}

/// <summary>
/// Implicitly converts an <see cref="string"/> to an <see cref="Authorisation1Choice"/>.
Expand All @@ -152,7 +157,12 @@ public void Switch(
/// <returns>
/// <see cref="Authorisation1Choice"/> instance representing the code.
/// </returns>
public static implicit operator Authorisation1Choice(string value) => CreateAsProprietary(value);

[return: NotNullIfNotNull(parameterName: nameof(value))]
public static implicit operator Authorisation1Choice? (string? value)
{
return value is null ? null : CreateAsProprietary(value);
}

/// <summary>
/// Determines whether the <see cref="Code"/> property should be serialized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ public void Switch(
/// <returns>
/// <see cref="Authorisation1Choice"/> instance representing the code.
/// </returns>
public static implicit operator Authorisation1Choice(string value) => CreateAsCode(value);

[return: NotNullIfNotNull(parameterName: nameof(value))]
public static implicit operator Authorisation1Choice? (string? value)
{
return value is null ? null : CreateAsCode(value);
}

/// <summary>
/// Implicitly converts an <see cref="TestNamespace.OtherNamespace.Authorisation1Code"/> to an <see cref="Authorisation1Choice"/>.
Expand All @@ -152,7 +157,12 @@ public void Switch(
/// <returns>
/// <see cref="Authorisation1Choice"/> instance representing the code.
/// </returns>
public static implicit operator Authorisation1Choice(TestNamespace.OtherNamespace.Authorisation1Code value) => CreateAsProprietary(value);

[return: NotNullIfNotNull(parameterName: nameof(value))]
public static implicit operator Authorisation1Choice? (TestNamespace.OtherNamespace.Authorisation1Code? value)
{
return value is null ? null : CreateAsProprietary(value.Value);
}

/// <summary>
/// Determines whether the <see cref="Proprietary"/> property should be serialized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,4 @@ public void ImplicitConversions_ShouldConvertCorrectly()

}
}