-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow something like "IgnorePrefix" on properties #619
Comments
Hey, unfortunately Mapperly doesn't support automatic unflattening yet. Instead you can try using [Mapper]
public static partial class Mapper
{
[MapProperty("FooBar", "Foo.Bar")]
public static partial Destination Map(Source src);
} |
This may get implemented by #594 |
Would it be worth adding regex support here? This way we don't have to add suffix and custom ignores as well. [MapperIgnore("Local\w*")] // ignores all members starting with "Local" |
@TimothyMakkison I have mixed feelings about regex since it adds a lot of complexity on the users side for probably really rare use-cases. |
@latonz Adding support for more flexible member matching would be really useful. I have a DTO where I have A LOT of AutoMapper has a feature to replace words and to recognize prefixes/suffixes. I think this is a quite common use case and the examples in their docs are quite practical. |
@InspiringCode this issue is about ignoring properties, so its related but not the same. |
@latonz Supporting regexes would be really valuable! Regarding member name replacing, we have to consider multiple scenarios:
Regarding point 1 and 2 my suggestion would be that the replacement is performed for both, the source and target property (similar to AutoMapper). Regarding point 3, one way to implement this would be to make the Attribute-properties arrays: [Mapper(ReplaceMemberNamesRegexes = ["(.+)InInputUnit", "Prsn" ], ReplaceMemberNamesWith=["$1", "Person"])] Another approach would be to introduce a new Regarding point 4: Ideally if one of the matched members is explicitly mapped, the explicit mapping should override the regex mapping like in the following example: [Mapper(ReplaceMemberNameRegex="(.+)InInputUnit", ReplaceMemberNameWith="$1")]
public partial class WeatherMapper {
[MapProperty(nameof(Weather.SpecialTemperature), nameof(WeatherDTO.SpecialTemperatureInInputUnit), Use=nameof(ConvertWithOffset))]
public partial WeatherDTO Map(Weather source);
} I would really love to see this feature in Mapperly. I have used it several times with AutoMapper and I am really missing it. |
You are describing even more advanced use-cases than I thought of.. This again increases the API complexity... 🤔 [MapperRenameProperty("(.+)InInputUnit", "$1")]
[MapperRenameProperty("Prsn", "Person")]
public partial class MyMapper; Explicit
You are referencing to |
@latonz |
Is your feature request related to a problem? Please describe.
I was trying to do a mapping and ran into an issue where I couldn't get the mapper to do it because the source and destination had slightly different prefixes.
Describe the solution you'd like
Something like
class IgnorePrefixAttribute(string SourcePrefix = null, string DestinationPrefix = null);
Describe alternatives you've considered
I tried making intermediary types that would have a dot notation to match what I wanted, but the source generator couldn't work it out, ie
Source: { FooBar }
Destination: X { Y Foo }, Y { bool Bar }
The text was updated successfully, but these errors were encountered: