private bool TryGetRetryOptionsFromAttribute()

in sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs [187:236]


            private bool TryGetRetryOptionsFromAttribute(AttributeData attribute, Location location, out GeneratorRetryOptions? retryOptions)
            {
                retryOptions = null;

                if (TryGetAttributeProperties(attribute, null, out IDictionary<string, object?>? attrProperties))
                {
                    retryOptions = new GeneratorRetryOptions();

                    // Would not expect this to fail since MaxRetryCount is a required value of a retry policy attribute
                    if (attrProperties!.TryGetValue(Constants.RetryConstants.MaxRetryCountKey, out object? maxRetryCount))
                    {
                        retryOptions.MaxRetryCount = maxRetryCount!.ToString();
                    }

                    // Check which strategy is being used by checking the attribute class
                    if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, _knownFunctionMetadataTypes.FixedDelayRetryAttribute))
                    {
                        retryOptions.Strategy = RetryStrategy.FixedDelay;

                        if (attrProperties.TryGetValue(Constants.RetryConstants.DelayIntervalKey, out object? delayInterval)) // nonnullable constructor arg of attribute, wouldn't expect this to fail
                        {
                            retryOptions.DelayInterval = delayInterval!.ToString();
                        }

                    }
                    else if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, _knownFunctionMetadataTypes.ExponentialBackoffRetryAttribute))
                    {
                        retryOptions.Strategy = RetryStrategy.ExponentialBackoff;

                        if (attrProperties.TryGetValue(Constants.RetryConstants.MinimumIntervalKey, out object? minimumInterval)) // nonnullable constructor arg of attribute, wouldn't expect this to fail
                        {
                            retryOptions.MinimumInterval = minimumInterval!.ToString();
                        }

                        if (attrProperties.TryGetValue(Constants.RetryConstants.MaximumIntervalKey, out object? maximumInterval)) // nonnullable constructor arg of attribute, wouldn't expect this to fail
                        {
                            retryOptions.MaximumInterval = maximumInterval!.ToString();
                        }
                    }
                    else
                    {
                        _context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.InvalidRetryOptions, location));
                        return false;
                    }

                    return true;
                }

                return false;
            }