Get comparison results
You can get project comparison results (IModelComparison
type) using the GetComparison
method of the IDiff
object. The GetComparison
method gets the most recent comparison result for the specified project.
tip
The GetComparison
method can also get the comparison result being displayed in the UI.
You can also get comparison information for a specified model using the GetMatch
method of the IModelComparison
object.
public void GetDifference(ICommandContext c, ICommandParams p)
{
//Get the comparison result for the current project
var project = c.App.Workspace.CurrentProject;
IModelComparison comparison = c.App.Diff.GetComparison(project);
//Output the difference information for the current model
var model = c.App.Workspace.CurrentModel;
IMatch match = comparison.GetMatch(model);
if (!match.HasDifference)
{
c.App.Output.WriteLine("Show Diff", "There are no differences.");
return;
}
foreach (IDifference difference in match.Differences)
{
if (difference.IsNewItem)
{
c.App.Output.WriteLine("Show Diff", "This is the model you added.");
}
if (difference.IsUpdateItem)
{
c.App.Output.WriteLine("Show Diff", $"Field: {difference.Field} was updated from {difference.OldValue} to {difference.NewValue}.");
}
}
}