private bool TryCreateBindingDictionary()

in sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs [564:611]


            private bool TryCreateBindingDictionary(AttributeData bindingAttrData, string bindingName, Location? bindingLocation, out IDictionary<string, object>? bindings, bool supportsDeferredBinding = false)
            {
                // Get binding info as a dictionary with keys as the property name and value as the property value
                if (!TryGetAttributeProperties(bindingAttrData, bindingLocation, out IDictionary<string, object?>? attributeProperties))
                {
                    bindings = null;
                    return false;
                }

                // Grab some required binding info properties
                string attributeName = bindingAttrData.AttributeClass!.Name;

                // properly format binding types by removing "Attribute" and "Input" descriptors
                string bindingType = attributeName.TrimStringsFromEnd(_functionsStringNamesToRemove).ToLowerFirstCharacter();

                // Set binding direction
                string bindingDirection = SymbolEqualityComparer.Default.Equals(bindingAttrData.AttributeClass?.BaseType, _knownFunctionMetadataTypes.OutputBindingAttribute) ? "Out" : "In";

                var bindingCount = attributeProperties!.Count + 3;
                bindings = new Dictionary<string, object>(capacity: bindingCount)
                {
                    { "name", bindingName },
                    { "type", bindingType },
                    { "direction", bindingDirection }
                };

                if (supportsDeferredBinding)
                {
                    bindings.Add("properties", new Dictionary<string, string>() { { "SupportsDeferredBinding", "True" } });
                }

                // Add additional bindingInfo to the anonymous type because some functions have more properties than others
                foreach (var prop in attributeProperties!) // attributeProperties won't be null here b/c we would've exited this method earlier if it was during TryGetAttributeProperties check
                {
                    var propertyName = prop.Key;

                    if (prop.Value?.GetType().IsArray ?? false)
                    {
                        bindings[propertyName] = prop.Value;
                    }
                    else
                    {
                        bindings[propertyName] = prop.Value!;
                    }
                }

                return true;
            }