/// <summary> /// Creates new config for <typeparamref name="TSource"/> and store it for non parametric extension /// <see cref="JsonPatchDocumentExtensions.GetColumnsNames{TModel}(Microsoft.AspNetCore.JsonPatch.JsonPatchDocument{TModel})"/>. /// </summary> /// <returns>New configuration.</returns> public static JsonPatchMapperConfig <TSource> NewConfig() { var config = new JsonPatchMapperConfig <TSource>(); JsonPatchMapperConfigStore.Instance.Add(config); return(config); }
/// <summary> /// Store configuration for mapping JSON patch of <typeparamref name="TSource"/> model to database names. /// </summary> /// <typeparam name="TSource">Type of model.</typeparam> /// <param name="jsonPatchMapperConfig"> /// Configuration for mapping JSON patch of <typeparamref name="TSource"/> model to database names. /// </param> public void Add <TSource>(JsonPatchMapperConfig <TSource> jsonPatchMapperConfig) where TSource : class => _configs.TryAdd(typeof(TSource), jsonPatchMapperConfig);
/// <summary> /// Get columns names from JSON patch operations path. /// </summary> /// <typeparam name="TModel">Patch model type.</typeparam> /// <param name="jsonPatch">JSON patch document.</param> /// <param name="patchMapperConfig">Mapping configuration.</param> /// <returns>Columns names.</returns> public static IEnumerable <string> GetColumnsNames <TModel>( this JsonPatchDocument <TModel> jsonPatch, JsonPatchMapperConfig <TModel> patchMapperConfig) where TModel : class => jsonPatch.Operations .Select(o => ((IJsonPatchMapper)patchMapperConfig).GetColumnName(o.path)) .Where(p => !p.IsNullOrEmpty());