From 7f1bc8c999cea773f385f908a866465e4b8e2dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Krch?= Date: Fri, 22 Nov 2024 10:04:53 +0100 Subject: [PATCH] #290 sample update --- .../ClassMappings/ClassMappingSample.cs | 15 +++++++++------ Migration.Tool.Extensions/README.md | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Migration.Tool.Extensions/ClassMappings/ClassMappingSample.cs b/Migration.Tool.Extensions/ClassMappings/ClassMappingSample.cs index 383f033d..61210025 100644 --- a/Migration.Tool.Extensions/ClassMappings/ClassMappingSample.cs +++ b/Migration.Tool.Extensions/ClassMappings/ClassMappingSample.cs @@ -170,14 +170,17 @@ public static IServiceCollection AddClassMergeExample(this IServiceCollection se startDate.ConvertFrom(sourceClassName2, "EventStartDateAsText", false, (v, context) => { - if (context is ConvertorTreeNodeContext(var nodeGuid, var nodeSiteId, var documentId, var migratingFromVersionHistory)) + switch (context) { - // here you can use available treenode context - } - else - { - // no context is available (possibly when tool is extended with other conversion possibilities) + case ConvertorTreeNodeContext treeNodeContext: + // here you can use available treenode context + // (var nodeGuid, int nodeSiteId, int? documentId, bool migratingFromVersionHistory) = treeNodeContext; + break; + default: + // no context is available (in future, mapping feature could be extended and therefore different context will be supplied or no context at all) + break; } + return v?.ToString() is { } av && !string.IsNullOrWhiteSpace(av) ? DateTime.Parse(av) : null; }); startDate.WithFieldPatch(f => f.Caption = "Event start date"); diff --git a/Migration.Tool.Extensions/README.md b/Migration.Tool.Extensions/README.md index 6b2cf2b7..c23805e2 100644 --- a/Migration.Tool.Extensions/README.md +++ b/Migration.Tool.Extensions/README.md @@ -66,8 +66,21 @@ var startDate = m.BuildField("StartDate"); startDate.SetFrom("_ET.Event1", "EventDateStart", true); // if needed use value conversion to adapt value startDate.ConvertFrom("_ET.Event2", "EventStartDateAsText", false, - v => v?.ToString() is { } av && !string.IsNullOrWhiteSpace(av) ? DateTime.Parse(av) : null -); + (v, context) => + { + switch (context) + { + case ConvertorTreeNodeContext treeNodeContext: + // here you can use available treenode context + // (var nodeGuid, int nodeSiteId, int? documentId, bool migratingFromVersionHistory) = treeNodeContext; + break; + default: + // no context is available (possibly when tool is extended with other conversion possibilities) + break; + } + + return v?.ToString() is { } av && !string.IsNullOrWhiteSpace(av) ? DateTime.Parse(av) : null; + }); startDate.WithFieldPatch(f => f.Caption = "Event start date"); ```