Ejemplo n.º 1
0
            public void Initialize(ExtensionConfigContext context)
            {
                var bindingFactory = context.Config.BindingFactory;

                var converterManager = bindingFactory.ConverterManager;

                converterManager.AddConverter <string, HttpRequestMessage, OutgoingHttpRequestAttribute>(
                    (body, attribute) => BuildHttpRequestMessage(attribute, new StringContent(body)));

                converterManager.AddConverter <HttpContent, HttpRequestMessage, OutgoingHttpRequestAttribute>(
                    (content, attribute) => BuildHttpRequestMessage(attribute, content));

                var bindingOut = bindingFactory.BindToAsyncCollector <OutgoingHttpRequestAttribute, HttpRequestMessage>((attrib, message) =>
                {
                    if (message.RequestUri == null)
                    {
                        message.RequestUri = new Uri(attrib.Uri);
                    }
                    message.Method = new HttpMethod("POST");
                    return(_client.SendAsync(message));
                });

                var bindingClient = bindingFactory.BindToExactType <OutgoingHttpRequestAttribute, HttpClient>(attrib => _client);

                var bindingProvider = bindingFactory.BindToGenericValueProvider <OutgoingHttpRequestAttribute>((attrib, paramType) =>
                {
                    return(Task.FromResult <IValueBinder>(new TextWriterValueBinder(attrib.Uri)));
                });

                context.RegisterBindingRules <OutgoingHttpRequestAttribute>(bindingOut, bindingClient, bindingProvider);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf   = context.Config.BindingFactory;
                var rule = bf.BindToInput <TestAttribute, AlphaType>(typeof(AlphaBuilder));

                context.RegisterBindingRules <TestAttribute>(rule);
            }
Ejemplo n.º 3
0
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // Add [Test] support
                var rule = bf.BindToGenericItem <TestAttribute>(Builder);

                context.RegisterBindingRules <TestAttribute>(rule);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;
                // No explicit converters -  just use implicit ones like inheritence
                var rule1 = bf.BindToInput <TestAttribute, AlphaDerivedType>(typeof(GeneralBuilder <>));
                var rule2 = bf.BindToInput <TestAttribute, object>(this); // 2nd rule

                context.RegisterBindingRules <TestAttribute>(rule1, rule2);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // Replaces BindToGeneric
                var rule = bf.BindToInput <TestAttribute, OpenType>(typeof(GeneralBuilder <>));

                context.RegisterBindingRules <TestAttribute>(rule);
            }
Ejemplo n.º 6
0
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // Add [Test] support
                var rule = bf.BindToExactType <TestAttribute, Widget>(attr => new Widget());

                context.RegisterBindingRules <TestAttribute>(ValidateAtIndexTime, rule);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // This is an error. The rule specifies OpenType,which allows any type.
                // But the builder can only produce Alpha types.
                var rule = bf.BindToInput <TestAttribute, OpenType>(typeof(AlphaBuilder));

                context.RegisterBindingRules <TestAttribute>(rule);
            }
Ejemplo n.º 8
0
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // Add [Test] support
                var rule         = bf.BindToExactType <TestAttribute, string>(attr => attr.Path);
                var ruleValidate = bf.AddFilter <TestAttribute>(Filter, rule);
                var rule2        = bf.BindToExactType <TestAttribute, string>(attr => "xxx");

                context.RegisterBindingRules <TestAttribute>(ruleValidate, rule2);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // Add [Test] support
                var rule         = bf.BindToInput <TestAttribute, string>(typeof(Converter1));
                var ruleValidate = bf.AddFilter <TestAttribute>(Filter, rule);
                var rule2        = bf.BindToInput <TestAttribute, string>(typeof(Converter2));

                context.RegisterBindingRules <TestAttribute>(ruleValidate, rule2);
            }
Ejemplo n.º 10
0
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // Add [Test] support
                var rule1          = bf.BindToExactType <TestAttribute, Widget>(attr => new Widget());
                var rule2          = bf.BindToExactType <TestAttribute, Widget2>(attr => new Widget2());
                var rule2Validator = bf.AddValidator <TestAttribute>(LocalValidator, rule2);

                context.RegisterBindingRules <TestAttribute>(rule2Validator, rule1);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                var cm = bf.ConverterManager;

                cm.AddConverter <AlphaType, BetaType>(ConvertAlpha2Beta);
                cm.AddConverter <BetaType, string>((beta) => $"Str({beta._value})");
                var rule = bf.BindToInput <TestAttribute, AlphaType>(typeof(AlphaBuilder));

                context.RegisterBindingRules <TestAttribute>(rule);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                bf.ConverterManager.AddConverter <AlphaType, BetaType>(ConvertAlpha2Beta);

                // The AlphaType restriction here means that although we have a GeneralBuilder<> that *could*
                // directly build a BetaType, we can only use it to build AlphaTypes, and so we must invoke the converter.
                var rule = bf.BindToInput <TestAttribute, AlphaType>(typeof(GeneralBuilder <>));

                context.RegisterBindingRules <TestAttribute>(rule);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                var cm = bf.ConverterManager;

                // Have an explicit converter to object.
                cm.AddConverter <AlphaType, object, TestAttribute>(this);

                var rule1 = bf.BindToInput <TestAttribute, AlphaType>(typeof(GeneralBuilder <>));

                context.RegisterBindingRules <TestAttribute>(rule1);
            }
            public void Initialize(ExtensionConfigContext context)
            {
                var bf = context.Config.BindingFactory;

                // The converter rule is the key switch.
                // If TParam==SingleType, then that means we can only convert from non-array types to AlphaType.
                //  that means object[] converts to AlphaType[]  (many)
                // If TParam==OpenType, then we can convert any type (including arrays) to an AlphaType.
                //  that means object[] converts to AlphaType (one)
                bf.ConverterManager.AddConverter <TParam, AlphaType, TestAttribute>(typeof(Object2AlphaConverter));

                var rule1 = bf.BindToCollector <TestAttribute, AlphaType>(this);

                context.RegisterBindingRules <TestAttribute>(rule1);
            }