Comments (4)
I assumed that the second enum is FlightSearchBaggageFilter. You just need to point the MapWith to a method that accepts a BaggageFilter enum and returns a FlightSearchBaggageFilter enum.
public enum BaggageFilter
{
Ignore,
Included,
}
public enum FlightSearchBaggageFilter
{
INCLUDED,
IGNORED,
}
public class MapsterConfiguration : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<BaggageFilter, FlightSearchBaggageFilter>().MapWith(x => ToFlightSearchBaggageFilter(x));
}
FlightSearchBaggageFilter ToFlightSearchBaggageFilter(BaggageFilter baggageFilter)
{
return baggageFilter switch
{
BaggageFilter.Ignore => FlightSearchBaggageFilter.IGNORED,
BaggageFilter.Included => FlightSearchBaggageFilter.INCLUDED,
_ => throw new ArgumentOutOfRangeException(nameof(baggageFilter), baggageFilter, "Out of range...")
};
}
}
from mapster.
Can you provide the enum definitions for BaggageFilter and FlightSearchBaggageFilter.
from mapster.
Can you provide the enum definitions for BaggageFilter and FlightSearchBaggageFilter.
Sorry for the late reply. I need to map these enums manually in config
public enum BaggageFilter
{
Ignore,
Included,
}
public enum BaggageFilter
{
INCLUDED,
IGNORED,
}
from mapster.
I assumed that the second enum is FlightSearchBaggageFilter. You just need to point the MapWith to a method that accepts a BaggageFilter enum and returns a FlightSearchBaggageFilter enum.
public enum BaggageFilter { Ignore, Included, } public enum FlightSearchBaggageFilter { INCLUDED, IGNORED, } public class MapsterConfiguration : IRegister { public void Register(TypeAdapterConfig config) { config.NewConfig<BaggageFilter, FlightSearchBaggageFilter>().MapWith(x => ToFlightSearchBaggageFilter(x)); } FlightSearchBaggageFilter ToFlightSearchBaggageFilter(BaggageFilter baggageFilter) { return baggageFilter switch { BaggageFilter.Ignore => FlightSearchBaggageFilter.IGNORED, BaggageFilter.Included => FlightSearchBaggageFilter.INCLUDED, _ => throw new ArgumentOutOfRangeException(nameof(baggageFilter), baggageFilter, "Out of range...") }; } }
It works, Thanks 👍
from mapster.
Related Issues (20)
- Support NET. 8.0 - Mapster.Tool HOT 2
- Update Mapster.Core to target netstandard2.0
- PreserveReference is using the src PropertyName to set the Destination property.
- Mapster tool How to declare custom mapping.
- Mapster re-writing value when mapping resulting in wrong destination type HOT 3
- Adapt to IList<T> does not update the destination IList<T>
- How Map From A Method Like Update ?
- Struggling with mapping readonly ICollection property
- EFcore uses ProjectToType mapping errors
- Destination and source type mismatch does not seem to be validated
- How can I obtain the changed field values after mapping two entities?
- New object is created on destination instead of null when using Adapt<> HOT 2
- Mapper NOT mapping capitalized abbreviations to record property names
- Adapt/AdaptToType DOES NOT working with anonymous object that returned from method
- Mapping hierarchies not working
- Mapping must be called using ServiceAdapter HOT 3
- Separate namespaces to avoid ambiguous references
- when leves proertiy is same name,its exception
- Mapping with constructor and default values for ignored properties? HOT 1
- Add Support for Conditional Access Expressions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapster.