Skip to content
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

Does Mapster work with Ardalis SmarteEnums? #735

Open
jeffreymonroe opened this issue Nov 9, 2024 · 1 comment
Open

Does Mapster work with Ardalis SmarteEnums? #735

jeffreymonroe opened this issue Nov 9, 2024 · 1 comment

Comments

@jeffreymonroe
Copy link

I see some discussion on #463, but there was no definitive answer. I defined a TypeAdapterConfig, but the below never gets called:

`
public class TypeContext : SmartEnum
{
public static readonly TypeContext None = new("Undefined", -1);
public static readonly TypeContext Device_DeviceType = new("Device.Type", 1);
public static readonly TypeContext Device_StateType = new ("Device.State", 2);
public static readonly TypeContext Site_SiteType = new ("Site.Type", 3);
public static readonly TypeContext Site_State = new ("Site.State", 4);
public static readonly TypeContext Telemetry_State = new ("Telemetry.State", 6);
public static readonly TypeContext Telemetry_DataType = new ("Telemetry.DataType", 7);
public static readonly TypeContext TelemetryNumericData_State = new ("TelemetryNumericData.State", 8);
public static readonly TypeContext TelemetryTextData_State = new ("TelemetryTextData.State", 9);
public static readonly TypeContext IngestLog_SeverityType = new("IngestLog.SeverityType", 10);

protected TypeContext(string name, int value) : base(name, value) { }

}
`

Then I add the TypeAdapterConfig before calling "Adapt":
TypeAdapterConfig<string, TypeContext>.NewConfig() .Map(d => d, s => TypeContext.FromName(s, true));

The TypeAdapterConfig is not called.

@stagep
Copy link

stagep commented Nov 9, 2024

The following MapWith works:

TypeAdapterConfig<string, TypeContext>.NewConfig().MapWith(d => TypeContext.FromName(d, true));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants