Skip to content

Commit

Permalink
#290 sample update
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Nov 22, 2024
1 parent 4efd444 commit 7f1bc8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 9 additions & 6 deletions Migration.Tool.Extensions/ClassMappings/ClassMappingSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 15 additions & 2 deletions Migration.Tool.Extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
```

Expand Down

0 comments on commit 7f1bc8c

Please sign in to comment.