Misleading exception message for ctor argument names
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia dalla chiamata a config.Compile() nell’esempio di constructor-mapping segnalato e traccia il modo in cui vengono associati i nomi degli argomenti del costruttore e il modo in cui viene prodotta l’eccezione no-default-constructor. Confronta il comportamento quando l’argomento si chiama number invece di id, quindi fai in modo che il risultato e il testo dell’eccezione riflettano le opzioni di constructor-mapping supportate e verifica lo scenario di mapping esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
There's an exception produced when mapping to a class with a ctor:
public class Destination
{
public Destination(int number)
{
Id = number;
}
public int Id { get; }
}
public class Source
{
public int Number { get; set; }
}
[Fact]
public void Should_Map()
{
var config = new TypeAdapterConfig();
config.ForType<Source, Destination>()
.Map(dest => dest.Id, source => source.Number);
config.Compile(); // throws an exception
}
The following exception is produced:
System.InvalidOperationException : No default constructor for type 'Destination', please use 'ConstructUsing' or 'MapWith'.
The exception message seems misleading as (I may have missed it in documentation) mapster seems to depend on argument names.
Renaming Destination ctor argument from number to id is enough for the test to succeed. That is, changing to the following:
public class Destination
{
public Destination(int id)
{
Id = id;
}
public int Id { get; }
}
Suggestions:
- maybe this name-dependency could be reduced?
- it would be great if the exception message could mention that there's an option of renaming ctor arguments to match the properties
- Lingua principale
- C#
- Stelle
- 5.2k
- Fork
- 411
- Merge medio
- 1g 8h
- PR unite (30g)
- 4
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MapsterMapper/Mapster
-
.NET MatrixAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
MapsterMapper/Mapster#1003 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
MapsterMapper/Mapster#1024 · 1 commento ·
-
[Mapster Tool] Add support for global:: to disambiguate type names in generated mappersForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaimprovement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
MapsterMapper/Mapster#1020 · 5 commenti ·
-
Mapster.Tool - PropertySettingBuilder.Map(member, mapFunc, targetPropertyName) method is not working as expected!Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
MapsterMapper/Mapster#1017 · 6 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
MapsterMapper/Mapster#1007 · 5 commenti ·
Tutte le issue di MapsterMapper/Mapster
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
unoplatform/uno.check#591 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
weaviate/csharp-client#378 ·
-
agentic-workflows automated testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Azure-Samples/Legacy-Modernization-Agents#194 ·
I maintainer di solito rispondono entro 1 giorno
-
area-encryption area-security p1-recommended technical-debt
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
V5: `asAllDay` parameter not working in `/feed/v5/calendar/sonarr.ics`Forse già presa @stevietv l’ha presa oggi. Apertaneeds-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno