diff --git a/src/Libraries/CoreNodeModels/DefineData.cs b/src/Libraries/CoreNodeModels/DefineData.cs index 24b8a3ef5c4..9e9e6ae6d8e 100644 --- a/src/Libraries/CoreNodeModels/DefineData.cs +++ b/src/Libraries/CoreNodeModels/DefineData.cs @@ -126,8 +126,6 @@ public DefineData() : base(">") { PropertyChanged += OnPropertyChanged; - //Items.Add(new DynamoDropDownItem("Select a type", null)); - foreach (var dataType in Data.DataNodeDynamoTypeList) { var displayName = dataType.Name; @@ -164,11 +162,8 @@ public override void Dispose() DataBridge.Instance.UnregisterCallback(GUID.ToString()); } - private static readonly string BuiltinDictionaryTypeName = typeof(DesignScript.Builtin.Dictionary).FullName; - private static readonly string BuiltinDictionaryGet = nameof(DesignScript.Builtin.Dictionary.ValueAtKey); - public override IEnumerable BuildOutputAst(List inputAstNodes) - { + { var resultAst = new List(); // function call inputs - reference to the function, and the function arguments coming from the inputs @@ -190,14 +185,15 @@ public override IEnumerable BuildOutputAst(List { functionCallIdentifier, AstFactory.BuildStringNode(">") }); + var safeExtractDictionaryValue = new Func, string, object>(DSCore.Data.SafeExtractDictionaryValue); + var getFirstKey = AstFactory.BuildFunctionCall(safeExtractDictionaryValue, + [functionCallIdentifier, AstFactory.BuildStringNode(">")]); resultAst.Add(AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), getFirstKey)); // Second get the key value pair to pass to the databridge callback - var getSecondKey = AstFactory.BuildFunctionCall(BuiltinDictionaryTypeName, BuiltinDictionaryGet, - new List { functionCallIdentifier, AstFactory.BuildStringNode("Validation") }); + var getSecondKey = AstFactory.BuildFunctionCall(safeExtractDictionaryValue, + [functionCallIdentifier, AstFactory.BuildStringNode("Validation")]); resultAst.Add(AstFactory.BuildAssignment( AstFactory.BuildIdentifier(GUID + "_db"), @@ -207,10 +203,6 @@ public override IEnumerable BuildOutputAst(List - /// Not sure at the moment how relevant is the databridge for this node type - /// - /// private void DataBridgeCallback(object data) { //Todo If the playerValue is not empty string then we can chanage the UI to reflect the value is coming from the player diff --git a/src/Libraries/CoreNodes/Data.cs b/src/Libraries/CoreNodes/Data.cs index 4b445206550..0064f77b1b1 100644 --- a/src/Libraries/CoreNodes/Data.cs +++ b/src/Libraries/CoreNodes/Data.cs @@ -648,6 +648,23 @@ static Data() DataNodeDynamoTypeList = new ReadOnlyCollection(typeList); } + /// + /// A helper function to safely extract a dictionary value + /// + /// The dictionary to extract the value from + /// The key of the key/value pair + /// + [IsVisibleInDynamoLibrary(false)] + public static object SafeExtractDictionaryValue(Dictionary dict, string key) + { + if (dict?.TryGetValue(key, out var value) == true) + { + return value; + } + + return null; + } + /// /// This is the function used by AST /// Handles some of the the node logic while performing the validation