MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.29k stars 327 forks source link

TypeAdapter.Adapt was already called, please clone or create new TypeAdapterConfig #559

Open LemonNoCry opened 1 year ago

LemonNoCry commented 1 year ago

Here is my code:

public static TTarget CopyTo<TSource, TTarget>(this TSource source, TTarget target, params Expression<Func<TTarget, object>>[] members)
    {
        if (source == null)
            return default;

        var config = TypeAdapterConfig<TSource, TTarget>
            .NewConfig()
            .IgnoreNullValues(true);

        if (members != null)
        {
            config.Ignore(members);
        }

        return source.Adapt(target, config.Config);
    }

I get some errors image

What's wrong with my writing