diff --git a/Migration.Tool.Extensions/ClassMappings/ClassMappingSample.cs b/Migration.Tool.Extensions/ClassMappings/ClassMappingSample.cs index 383f033d..16844d0f 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 (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"); 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"); ```