public string TemplateBind()

in src/WebJobs.Extensions.CosmosDB/CosmosDBSqlResolutionPolicy.cs [16:47]


        public string TemplateBind(PropertyInfo propInfo, Attribute resolvedAttribute, BindingTemplate bindingTemplate, IReadOnlyDictionary<string, object> bindingData)
        {
            if (bindingTemplate == null)
            {
                throw new ArgumentNullException(nameof(bindingTemplate));
            }

            if (bindingData == null)
            {
                throw new ArgumentNullException(nameof(bindingData));
            }

            CosmosDBAttribute docDbAttribute = resolvedAttribute as CosmosDBAttribute;
            if (docDbAttribute == null)
            {
                throw new NotSupportedException($"This policy is only supported for {nameof(CosmosDBAttribute)}.");
            }

            // also build up a dictionary replacing '{token}' with '@token' 
            IDictionary<string, string> replacements = new Dictionary<string, string>();
            List<(string, object)> parameters = new List<(string, object)>();
            foreach (var token in bindingTemplate.ParameterNames.Distinct())
            {
                string sqlToken = $"@{token}";
                parameters.Add((sqlToken, bindingData[token]));
                replacements.Add(token, sqlToken);
            }

            docDbAttribute.SqlQueryParameters = parameters;

            return bindingTemplate.Bind(new ReadOnlyDictionary<string, string>(replacements));
        }