Struct tweaks
This commit is contained in:
parent
e314387772
commit
eb32ef8e94
|
@ -60,8 +60,8 @@ namespace MapTo
|
||||||
{
|
{
|
||||||
MappingContext context = typeSyntax switch
|
MappingContext context = typeSyntax switch
|
||||||
{
|
{
|
||||||
ClassDeclarationSyntax => new ClassMappingContext(compilation, sourceGenerationOptions, typeSyntax),
|
|
||||||
StructDeclarationSyntax => new StructMappingContext(compilation, sourceGenerationOptions, typeSyntax),
|
StructDeclarationSyntax => new StructMappingContext(compilation, sourceGenerationOptions, typeSyntax),
|
||||||
|
ClassDeclarationSyntax => new ClassMappingContext(compilation, sourceGenerationOptions, typeSyntax),
|
||||||
RecordDeclarationSyntax => new RecordMappingContext(compilation, sourceGenerationOptions, typeSyntax),
|
RecordDeclarationSyntax => new RecordMappingContext(compilation, sourceGenerationOptions, typeSyntax),
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,17 +18,11 @@ namespace MapTo.Sources
|
||||||
.WriteOpeningBracket()
|
.WriteOpeningBracket()
|
||||||
|
|
||||||
// Class declaration
|
// Class declaration
|
||||||
.WriteLine($"partial class {model.TypeIdentifierName}")
|
.WriteLine($"partial struct {model.TypeIdentifierName}")
|
||||||
.WriteOpeningBracket();
|
.WriteOpeningBracket();
|
||||||
|
|
||||||
// Class body
|
// Class body
|
||||||
if (model.GenerateSecondaryConstructor)
|
|
||||||
{
|
|
||||||
builder
|
|
||||||
.GenerateSecondaryConstructor(model)
|
|
||||||
.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.GeneratePrivateConstructor(model)
|
.GeneratePrivateConstructor(model)
|
||||||
.WriteLine()
|
.WriteLine()
|
||||||
|
@ -50,7 +44,7 @@ namespace MapTo.Sources
|
||||||
{
|
{
|
||||||
builder
|
builder
|
||||||
.WriteLine("/// <summary>")
|
.WriteLine("/// <summary>")
|
||||||
.WriteLine($"/// Initializes a new instance of the <see cref=\"{model.TypeIdentifierName}\"/> class")
|
.WriteLine($"/// Initializes a new instance of the <see cref=\"{model.TypeIdentifierName}\"/> struct")
|
||||||
.WriteLine($"/// using the property values from the specified <paramref name=\"{sourceClassParameterName}\"/>.")
|
.WriteLine($"/// using the property values from the specified <paramref name=\"{sourceClassParameterName}\"/>.")
|
||||||
.WriteLine("/// </summary>")
|
.WriteLine("/// </summary>")
|
||||||
.WriteLine($"/// <exception cref=\"ArgumentNullException\">{sourceClassParameterName} is null</exception>");
|
.WriteLine($"/// <exception cref=\"ArgumentNullException\">{sourceClassParameterName} is null</exception>");
|
||||||
|
@ -115,22 +109,7 @@ namespace MapTo.Sources
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static SourceBuilder GenerateConvertorMethodsXmlDocs(this SourceBuilder builder, MappingModel model, string sourceClassParameterName)
|
|
||||||
{
|
|
||||||
if (!model.Options.GenerateXmlDocument)
|
|
||||||
{
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder
|
|
||||||
.WriteLine("/// <summary>")
|
|
||||||
.WriteLine($"/// Creates a new instance of <see cref=\"{model.TypeIdentifierName}\"/> and sets its participating properties")
|
|
||||||
.WriteLine($"/// using the property values from <paramref name=\"{sourceClassParameterName}\"/>.")
|
|
||||||
.WriteLine("/// </summary>")
|
|
||||||
.WriteLine($"/// <param name=\"{sourceClassParameterName}\">The instance of <see cref=\"{model.SourceType}\"/> to use as source.</param>")
|
|
||||||
.WriteLine($"/// <returns>A new instance of <see cred=\"{model.TypeIdentifierName}\"/> -or- <c>null</c> if <paramref name=\"{sourceClassParameterName}\"/> is <c>null</c>.</returns>");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SourceBuilder GenerateUpdaterMethodsXmlDocs(this SourceBuilder builder, MappingModel model, string sourceClassParameterName)
|
private static SourceBuilder GenerateUpdaterMethodsXmlDocs(this SourceBuilder builder, MappingModel model, string sourceClassParameterName)
|
||||||
{
|
{
|
||||||
|
@ -147,26 +126,5 @@ namespace MapTo.Sources
|
||||||
.WriteLine($"/// <param name=\"{sourceClassParameterName}\">The instance of <see cref=\"{model.SourceType}\"/> to use as source.</param>");
|
.WriteLine($"/// <param name=\"{sourceClassParameterName}\">The instance of <see cref=\"{model.SourceType}\"/> to use as source.</param>");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SourceBuilder GenerateSourceTypeExtensionClass(this SourceBuilder builder, MappingModel model)
|
|
||||||
{
|
|
||||||
return builder
|
|
||||||
.WriteLine($"{model.Options.GeneratedMethodsAccessModifier.ToLowercaseString()} static partial class {model.SourceTypeIdentifierName}To{model.TypeIdentifierName}Extensions")
|
|
||||||
.WriteOpeningBracket()
|
|
||||||
.GenerateSourceTypeExtensionMethod(model)
|
|
||||||
.WriteClosingBracket();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SourceBuilder GenerateSourceTypeExtensionMethod(this SourceBuilder builder, MappingModel model)
|
|
||||||
{
|
|
||||||
var sourceClassParameterName = model.SourceTypeIdentifierName.ToCamelCase();
|
|
||||||
|
|
||||||
return builder
|
|
||||||
.GenerateConvertorMethodsXmlDocs(model, sourceClassParameterName)
|
|
||||||
.WriteLineIf(model.Options.SupportNullableStaticAnalysis, $"[return: NotNullIfNotNull(\"{sourceClassParameterName}\")]")
|
|
||||||
.WriteLine($"{model.Options.GeneratedMethodsAccessModifier.ToLowercaseString()} static {model.TypeIdentifierName}{model.Options.NullableReferenceSyntax} To{model.TypeIdentifierName}(this {model.SourceType}{model.Options.NullableReferenceSyntax} {sourceClassParameterName})")
|
|
||||||
.WriteOpeningBracket()
|
|
||||||
.WriteLine($"return {sourceClassParameterName} == null ? null : new {model.TypeIdentifierName}({sourceClassParameterName});")
|
|
||||||
.WriteClosingBracket();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue