コード例 #1
0
        public static void RegisterOptimizer(
            IDictionary <string, object?> contextData,
            ISelectionSetOptimizer optimizer)
        {
            if (contextData.TryGetValue(_key, out object?value) &&
                value is List <ISelectionSetOptimizer> optimizers &&
                !optimizers.Contains(optimizer))
            {
                optimizers.Add(optimizer);
                return;
            }

            optimizers = new List <ISelectionSetOptimizer> {
                optimizer
            };
            contextData[_key] = optimizers;
        }
        public static IObjectFieldDescriptor UseOptimizer(
            this IObjectFieldDescriptor descriptor,
            ISelectionSetOptimizer optimizer)
        {
            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (optimizer is null)
            {
                throw new ArgumentNullException(nameof(optimizer));
            }

            descriptor
            .Extend()
            .OnBeforeCreate(d => RegisterOptimizer(d.ContextData, optimizer));

            return(descriptor);
        }