Update method when properties are not readonly
This commit is contained in:
parent
55f735006e
commit
1e266bfd3f
|
@ -137,6 +137,8 @@ namespace MapTo
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
string? converterFullyQualifiedName = null;
|
||||
var converterParameters = ImmutableArray<string>.Empty;
|
||||
ITypeSymbol? mappedSourcePropertyType = null;
|
||||
|
@ -162,7 +164,9 @@ namespace MapTo
|
|||
converterParameters.ToImmutableArray(),
|
||||
sourceProperty.Name,
|
||||
ToQualifiedDisplayName(mappedSourcePropertyType),
|
||||
ToQualifiedDisplayName(enumerableTypeArgumentType));
|
||||
ToQualifiedDisplayName(enumerableTypeArgumentType),
|
||||
(sourceProperty as IPropertySymbol).IsReadOnly);
|
||||
;
|
||||
}
|
||||
|
||||
protected bool TryGetMapTypeConverter(ISymbol property, IPropertySymbol sourceProperty, out string? converterFullyQualifiedName,
|
||||
|
|
|
@ -29,7 +29,8 @@ namespace MapTo
|
|||
ImmutableArray<string> TypeConverterParameters,
|
||||
string SourcePropertyName,
|
||||
string? MappedSourcePropertyTypeName,
|
||||
string? EnumerableTypeArgument)
|
||||
string? EnumerableTypeArgument,
|
||||
bool isReadOnly)
|
||||
{
|
||||
public bool IsEnumerable => EnumerableTypeArgument is not null;
|
||||
}
|
||||
|
|
|
@ -21,17 +21,24 @@ namespace MapTo.Sources
|
|||
.WriteLine($"partial class {model.TypeIdentifierName}")
|
||||
.WriteOpeningBracket();
|
||||
|
||||
// Class body
|
||||
/*if (model.GenerateSecondaryConstructor)
|
||||
{
|
||||
builder
|
||||
.GenerateSecondaryConstructor(model)
|
||||
.WriteLine();
|
||||
}*/
|
||||
|
||||
// Class body
|
||||
/*if (model.GenerateSecondaryConstructor)
|
||||
{
|
||||
builder
|
||||
.GeneratePrivateConstructor(model)
|
||||
.WriteLine()
|
||||
.GenerateSecondaryConstructor(model)
|
||||
.WriteLine();
|
||||
}*/
|
||||
|
||||
builder
|
||||
.GeneratePrivateConstructor(model)
|
||||
.WriteLine();
|
||||
|
||||
if(PropertiesAreReadOnly(model))
|
||||
{
|
||||
builder.GenerateUpdateMethod(model);
|
||||
}
|
||||
|
||||
builder
|
||||
//.GenerateFactoryMethod(model)
|
||||
.GenerateUpdateMethod(model)
|
||||
|
||||
|
@ -105,7 +112,7 @@ namespace MapTo.Sources
|
|||
{
|
||||
builder.WriteLine(property.MappedSourcePropertyTypeName is null
|
||||
? $"{property.Name} = {sourceClassParameterName}.{property.SourcePropertyName};"
|
||||
: $"{property.Name} = {mappingContextParameterName}.{MappingContextSource.MapMethodName}<{property.MappedSourcePropertyTypeName}, {property.Type}>({sourceClassParameterName}.{property.SourcePropertyName});");
|
||||
: "");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -123,6 +130,16 @@ namespace MapTo.Sources
|
|||
|
||||
}
|
||||
|
||||
private static bool PropertiesAreReadOnly(MappingModel model)
|
||||
{
|
||||
foreach (var property in model.MappedProperties)
|
||||
{
|
||||
if (!property.isReadOnly) return false;
|
||||
}
|
||||
return true ;
|
||||
|
||||
}
|
||||
|
||||
private static SourceBuilder GenerateFactoryMethod(this SourceBuilder builder, MappingModel model)
|
||||
{
|
||||
var sourceClassParameterName = model.SourceTypeIdentifierName.ToCamelCase();
|
||||
|
|
Loading…
Reference in New Issue