internal void EnsureReferenceInfo()

in ExpressionBuilder/ExpressionBuilder/ExpressionNodes/ExpressionBuilder.ExpressionNode.cs [260:313]


        internal void EnsureReferenceInfo()
        {
            if (_objRefList == null)
            {
                // Get all ReferenceNodes in this expression
                HashSet<ReferenceNode> referenceNodes = new HashSet<ReferenceNode>();
                PopulateParameterNodes(ref _constParamMap, ref referenceNodes);

                // Find all CompositionObjects across all referenceNodes that need a paramName to be created
                HashSet<CompositionObject> compObjects = new HashSet<CompositionObject>();
                foreach (var refNode in referenceNodes)
                {
                    if ((refNode.Reference != null) && (refNode.GetReferenceParamString() == null))
                    {
                        compObjects.Add(refNode.Reference);
                    }
                }

                // Create a map to store the generated paramNames for each CompObj
                uint id = 0;
                _compObjToParamNameMap = new Dictionary<CompositionObject, string>();
                foreach (var compObj in compObjects)
                {
                    // compObj.ToString() will return something like "Microsoft.UI.Composition.SpriteVisual"
                    // Make it look like "SpriteVisual_1"
                    string paramName = compObj.ToString();
                    paramName = $"{paramName.Substring(paramName.LastIndexOf('.') + 1)}_{++id}";       // make sure the created param name doesn't overwrite a custom name

                    _compObjToParamNameMap.Add(compObj, paramName);
                }

                // Go through all reference nodes again to create our full list of referenceInfo. This time, if 
                // the param name is null, look it up from our new map and store it.
                _objRefList = new List<ReferenceInfo>();
                foreach (var refNode in referenceNodes)
                {
                    string paramName = refNode.GetReferenceParamString();

                    if ((refNode.Reference == null) && (paramName == null))
                    {
                        // This can't happen - if the ref is null it must be because it's a named param
                        throw new Exception("Reference and paramName can't both be null");
                    }

                    if (paramName == null)
                    {
                        paramName = _compObjToParamNameMap[refNode.Reference];
                    }

                    _objRefList.Add(new ReferenceInfo(paramName, refNode.Reference));
                    refNode._paramName = paramName;
                }
            }
        }