You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like there's no functionality to map differently cased fields with without underscores.
For example, using the Flexible strategy, FOOBAR will map to Foobar, but not FooBar. This is due to it being treated as one word for PascalCase matching. Not sure if it was intentionally excluded or is already possible somehow, but it would be useful IMO to have an IgnoreCase matching strategy, which would match FOOBAR to FooBar, fOObAR, foobar etc.
I've implemented this on my build, and it seems to be a fairly simple addition. However, I'm unaware of how it might affect performance, other than OrdinalIgnoreCase giving a faster string comparison.
In NameMatchingStrategy.cs, add an IgnoreCase property:
public bool? IgnoreCase { get; set; }
public void Apply(NameMatchingStrategy other)
{
if (this.SourceMemberNameConverter == null)
this.SourceMemberNameConverter = other.SourceMemberNameConverter;
if (this.DestinationMemberNameConverter == null)
this.DestinationMemberNameConverter = other.DestinationMemberNameConverter;
if (this.IgnoreCase == null)
this.IgnoreCase = other.IgnoreCase;
}
public static readonly NameMatchingStrategy Exact = new NameMatchingStrategy(Identity, Identity);
public static readonly NameMatchingStrategy Flexible = new NameMatchingStrategy(PascalCase, PascalCase);
public static readonly NameMatchingStrategy ToCamelCase = new NameMatchingStrategy(CamelCase, Identity);
public static readonly NameMatchingStrategy FromCamelCase = new NameMatchingStrategy(Identity, CamelCase);
public static readonly NameMatchingStrategy Caseless = new NameMatchingStrategy(Identity, Identity, true);
public NameMatchingStrategy(Func<string, string> sourceMemberNameConverter, Func<string, string> destinationMemberNameConverter, bool ignoreCase = false)
{
SourceMemberNameConverter = sourceMemberNameConverter;
DestinationMemberNameConverter = destinationMemberNameConverter;
IgnoreCase = ignoreCase;
}
public NameMatchingStrategy()
{
}
I also added a constructor here to allow the IgnoreCase property to be specified independently of the templates.
In ValueAccessingStrategy.cs, PropertyOrFieldFn, use .Equals() with StringComparison instead of ==:
GetMethodFn and DictionaryFn would also require this.
When setting the NameMatchingStrategy (using GlobalSettings, for example) you can then do something like this:
TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy(
new NameMatchingStrategy(NameMatchingStrategy.Identity, NameMatchingStrategy.Identity, true));
The text was updated successfully, but these errors were encountered:
It looks like there's no functionality to map differently cased fields with without underscores.
For example, using the Flexible strategy, FOOBAR will map to Foobar, but not FooBar. This is due to it being treated as one word for PascalCase matching. Not sure if it was intentionally excluded or is already possible somehow, but it would be useful IMO to have an IgnoreCase matching strategy, which would match FOOBAR to FooBar, fOObAR, foobar etc.
I've implemented this on my build, and it seems to be a fairly simple addition. However, I'm unaware of how it might affect performance, other than OrdinalIgnoreCase giving a faster string comparison.
In NameMatchingStrategy.cs, add an IgnoreCase property:
I also added a constructor here to allow the IgnoreCase property to be specified independently of the templates.
In ValueAccessingStrategy.cs, PropertyOrFieldFn, use .Equals() with StringComparison instead of ==:
GetMethodFn and DictionaryFn would also require this.
When setting the NameMatchingStrategy (using GlobalSettings, for example) you can then do something like this:
The text was updated successfully, but these errors were encountered: