Cleanup.
This commit is contained in:
parent
0fc9540c58
commit
2ef7ded450
|
@ -23,7 +23,7 @@ namespace MapTo
|
|||
Create($"{ErrorId}030", location, "Type Mismatch", $"No matching properties found between '{classType.ToDisplayString()}' and '{sourceType.ToDisplayString()}' types.");
|
||||
|
||||
internal static Diagnostic NoMatchingPropertyTypeFoundError(IPropertySymbol property) =>
|
||||
Create($"{ErrorId}031", property.Locations.FirstOrDefault(), "Type Mismatch", $"Cannot create a map for '{property.ToDisplayString()}' property because source and destination types are not implicitly convertible. Consider using '{MapTypeConverterAttributeSource.FullyQualifiedName}' to provide a type converter or ignore the property using '{RootNamespace}.{IgnorePropertyAttributeSource.AttributeName}Attribute'.");
|
||||
Create($"{ErrorId}031", property.Locations.FirstOrDefault(), "Type Mismatch", $"Cannot create a map for '{property.ToDisplayString()}' property because source and destination types are not implicitly convertible. Consider using '{MapTypeConverterAttributeSource.FullyQualifiedName}' to provide a type converter or ignore the property using '{IgnorePropertyAttributeSource.FullyQualifiedName}'.");
|
||||
|
||||
internal static Diagnostic InvalidTypeConverterGenericTypesError(IPropertySymbol property, IPropertySymbol sourceProperty) =>
|
||||
Create($"{ErrorId}032", property.Locations.FirstOrDefault(), "Type Mismatch", $"Cannot map '{property.ToDisplayString()}' property because the annotated converter does not implement '{RootNamespace}.{TypeConverterSource.InterfaceName}<{sourceProperty.Type.ToDisplayString()}, {property.Type.ToDisplayString()}>'.");
|
||||
|
|
|
@ -5,7 +5,8 @@ namespace MapTo.Sources
|
|||
internal static class IgnorePropertyAttributeSource
|
||||
{
|
||||
internal const string AttributeName = "IgnoreProperty";
|
||||
internal const string FullyQualifiedName = RootNamespace + "." + AttributeName + "Attribute";
|
||||
internal const string AttributeClassName = AttributeName + "Attribute";
|
||||
internal const string FullyQualifiedName = RootNamespace + "." + AttributeClassName;
|
||||
|
||||
internal static SourceCode Generate(SourceGenerationOptions options)
|
||||
{
|
||||
|
@ -26,10 +27,10 @@ namespace MapTo.Sources
|
|||
|
||||
builder
|
||||
.WriteLine("[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]")
|
||||
.WriteLine($"public sealed class {AttributeName}Attribute : Attribute {{ }}")
|
||||
.WriteLine($"public sealed class {AttributeClassName} : Attribute {{ }}")
|
||||
.WriteClosingBracket();
|
||||
|
||||
return new(builder.ToString(), $"{AttributeName}Attribute.g.cs");
|
||||
return new(builder.ToString(), $"{AttributeClassName}.g.cs");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@ namespace MapTo.Sources
|
|||
internal static class MapFromAttributeSource
|
||||
{
|
||||
internal const string AttributeName = "MapFrom";
|
||||
internal const string AttributeClassName = AttributeName + "Attribute";
|
||||
internal const string FullyQualifiedName = RootNamespace + "." + AttributeClassName;
|
||||
|
||||
internal static SourceCode Generate(SourceGenerationOptions options)
|
||||
{
|
||||
|
|
|
@ -23,12 +23,12 @@ namespace MapTo.Sources
|
|||
{
|
||||
builder
|
||||
.WriteLine("/// <summary>")
|
||||
.WriteLine("/// Maps a property to property of another object.")
|
||||
.WriteLine("/// Specifies what type to use as a converter for the property this attribute is bound to.")
|
||||
.WriteLine("/// </summary>");
|
||||
}
|
||||
|
||||
builder
|
||||
.WriteLine("[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]")
|
||||
.WriteLine("[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]")
|
||||
.WriteLine($"public sealed class {AttributeClassName} : Attribute")
|
||||
.WriteOpeningBracket();
|
||||
|
||||
|
@ -51,7 +51,7 @@ namespace MapTo.Sources
|
|||
{
|
||||
builder
|
||||
.WriteLine("/// <summary>")
|
||||
.WriteLine("/// Gets or sets the <see cref=\"ITypeConverter{TSource,TDestination}\" /> to be used to convert the source type.")
|
||||
.WriteLine($"/// Gets or sets the <see cref=\"{TypeConverterSource.InterfaceName}{{TSource,TDestination}}\" /> to be used to convert the source type.")
|
||||
.WriteLine("/// </summary>");
|
||||
}
|
||||
|
||||
|
|
|
@ -527,7 +527,7 @@ using System;
|
|||
|
||||
namespace MapTo
|
||||
{{
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
public sealed class MapTypeConverterAttribute : Attribute
|
||||
{{
|
||||
public MapTypeConverterAttribute(Type converter)
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace TestConsoleApp.ViewModels
|
|||
[IgnoreProperty]
|
||||
public string LastName { get; }
|
||||
|
||||
[MapProperty(Converter = typeof(LastNameConverter))]
|
||||
[MapTypeConverter(typeof(LastNameConverter))]
|
||||
public string Key { get; }
|
||||
|
||||
private class LastNameConverter : ITypeConverter<long, string>
|
||||
|
|
Loading…
Reference in New Issue