diff --git a/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs b/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs index bae621d2758..0f99bb0a5f7 100644 --- a/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs @@ -249,6 +249,9 @@ public WatchViewModel(string label, string path, Action tagGeometry, boo private static string GetStringFromObject(object obj) { + if (obj == null) + return Resources.NullString; + TypeCode type = Type.GetTypeCode(obj.GetType()); switch (type) { @@ -285,6 +288,9 @@ private static string ObjectToLabelString(object obj) private string GetDisplayType(object obj) { + if (obj == null) + return Resources.NullString; + TypeCode typeCode = Type.GetTypeCode(obj.GetType()); // returning a customized user friendly string instead of just returning the name of the type switch (typeCode) diff --git a/test/DynamoCoreWpfTests/WatchNodeTests.cs b/test/DynamoCoreWpfTests/WatchNodeTests.cs index 8681147d4f4..2a40c834e44 100644 --- a/test/DynamoCoreWpfTests/WatchNodeTests.cs +++ b/test/DynamoCoreWpfTests/WatchNodeTests.cs @@ -256,6 +256,29 @@ public void WatchNestedDictionary() Assert.AreEqual(2, watchVM.NumberOfItems); } + [Test] + public void WatchDictionary() + { + string openPath = Path.Combine(TestDirectory, @"core\watch\WatchDictionary.dyn"); + ViewModel.OpenCommand.Execute(openPath); + ViewModel.HomeSpace.Run(); + + var watchNode = ViewModel.Model.CurrentWorkspace.NodeFromWorkspace("daa19ed1-36b0-4586-ae11-6470e7c196bd") as Watch; + + var watchVM = GetWatchViewModel(watchNode); + + Assert.AreEqual(3, watchVM.Children.Count); + + Assert.AreEqual("1", watchVM.Children.ElementAt(0).NodeLabel); + Assert.AreEqual("Int64", watchVM.Children.ElementAt(0).ValueType); + + Assert.AreEqual("null", watchVM.Children.ElementAt(1).NodeLabel); + Assert.AreEqual("null", watchVM.Children.ElementAt(1).ValueType); + + Assert.AreEqual("null", watchVM.Children.ElementAt(2).NodeLabel); + Assert.AreEqual("String", watchVM.Children.ElementAt(2).ValueType); + } + [Test] public void WatchNumber() { diff --git a/test/core/watch/WatchDictionary.dyn b/test/core/watch/WatchDictionary.dyn new file mode 100644 index 00000000000..6ba5567c928 --- /dev/null +++ b/test/core/watch/WatchDictionary.dyn @@ -0,0 +1,144 @@ +{ + "Uuid": "b3971a38-9e42-4229-9ebd-7fa012a6ac9b", + "IsCustomNode": false, + "Description": "", + "Name": "WatchDictionary", + "ElementResolver": { + "ResolutionMap": { + "DesignScript.Builtin.Dictionary": { + "Key": "DesignScript.Builtin.Dictionary", + "Value": "DesignScriptBuiltin.dll" + } + } + }, + "Inputs": [], + "Outputs": [], + "Nodes": [ + { + "ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore", + "Id": "275d5ff387254cfa9ff92fac8f2d0e11", + "NodeType": "CodeBlockNode", + "Inputs": [], + "Outputs": [ + { + "Id": "1b7713c8f66d4e38933b4fb97acc7a28", + "Name": "", + "Description": "Value of expression at line 1", + "UsingDefaultValue": false, + "Level": 2, + "UseLevels": false, + "KeepListStructure": false + } + ], + "Replication": "Disabled", + "Description": "Allows for DesignScript code to be authored directly", + "Code": "{\"a\":1, \"b\": \"null\", \"c\": null};" + }, + { + "ConcreteType": "CoreNodeModels.Watch, CoreNodeModels", + "Id": "daa19ed136b04586ae116470e7c196bd", + "NodeType": "ExtensionNode", + "Inputs": [ + { + "Id": "7ce251e0efc946ce85c17be979c34247", + "Name": "", + "Description": "Node to show output from", + "UsingDefaultValue": false, + "Level": 2, + "UseLevels": false, + "KeepListStructure": false + } + ], + "Outputs": [ + { + "Id": "7cbf667c84fa4df3a7d6983d5a2e5825", + "Name": "", + "Description": "Node output", + "UsingDefaultValue": false, + "Level": 2, + "UseLevels": false, + "KeepListStructure": false + } + ], + "Replication": "Disabled", + "Description": "Visualizes a node's output" + } + ], + "Connectors": [ + { + "Start": "1b7713c8f66d4e38933b4fb97acc7a28", + "End": "7ce251e0efc946ce85c17be979c34247", + "Id": "b903a06b6a534010862862dc48bd30b8", + "IsHidden": "False" + } + ], + "Dependencies": [], + "NodeLibraryDependencies": [], + "Thumbnail": "", + "GraphDocumentationURL": null, + "ExtensionWorkspaceData": [ + { + "ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670", + "Name": "Properties", + "Version": "2.18", + "Data": {} + } + ], + "Author": "", + "Linting": { + "activeLinter": "None", + "activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a", + "warningCount": 0, + "errorCount": 0 + }, + "Bindings": [], + "View": { + "Dynamo": { + "ScaleFactor": 1.0, + "HasRunWithoutCrash": true, + "IsVisibleInDynamoLibrary": true, + "Version": "2.18.0.2986", + "RunType": "Automatic", + "RunPeriod": "1000" + }, + "Camera": { + "Name": "_Background Preview", + "EyeX": -17.0, + "EyeY": 24.0, + "EyeZ": 50.0, + "LookX": 12.0, + "LookY": -13.0, + "LookZ": -58.0, + "UpX": 0.0, + "UpY": 1.0, + "UpZ": 0.0 + }, + "ConnectorPins": [], + "NodeViews": [ + { + "Id": "275d5ff387254cfa9ff92fac8f2d0e11", + "Name": "Code Block", + "IsSetAsInput": false, + "IsSetAsOutput": false, + "Excluded": false, + "ShowGeometry": true, + "X": 220.5, + "Y": 325.0 + }, + { + "Id": "daa19ed136b04586ae116470e7c196bd", + "Name": "Watch", + "IsSetAsInput": false, + "IsSetAsOutput": false, + "Excluded": false, + "ShowGeometry": true, + "X": 656.5, + "Y": 399.0 + } + ], + "Annotations": [], + "X": 0.0, + "Y": 0.0, + "Zoom": 1.0 + } +} \ No newline at end of file