示例#1
0
        public override PolicyMethodBinding BindMethod(
            MethodRule rule, MethodDispatch dispatch,
            DefinitionAttribute attribute)
        {
            var binding = base.BindMethod(rule, dispatch, attribute);

            InferVariance(binding);
            return(binding);
        }
示例#2
0
 protected MethodBinding(MethodDispatch dispatch)
 {
     if (dispatch == null)
     {
         throw new ArgumentNullException(nameof(dispatch));
     }
     Dispatcher = dispatch;
     AddFilters(FilterAttribute.GetFilters(Dispatcher.Method));
 }
 private object GetCallbackInfo(object callback, object[] args,
                                MethodDispatch dispatcher, out Type callbackType)
 {
     if (CallbackIndex.HasValue)
     {
         var index = CallbackIndex.Value;
         callbackType = dispatcher.Parameters[index].ParameterType;
         return(args[index]);
     }
     callbackType = callback.GetType();
     return(callback);
 }
示例#4
0
        public PolicyMethodBinding Bind(MethodDispatch dispatch, DefinitionAttribute attribute)
        {
            var binding = _binder(this, dispatch, attribute);

            _returnValue?.Configure(binding);
            var parameters = dispatch.Method.GetParameters();

            for (var i = 0; i < parameters.Length; ++i)
            {
                _args[i].Configure(parameters[i], binding);
            }
            return(binding);
        }
 public PolicyMethodBinding(MethodRule rule,
                            MethodDispatch dispatch,
                            DefinitionAttribute attribute,
                            CallbackPolicy policy)
     : base(dispatch)
 {
     if (rule == null)
     {
         throw new ArgumentNullException(nameof(rule));
     }
     if (dispatch == null)
     {
         throw new ArgumentNullException(nameof(dispatch));
     }
     Rule      = rule;
     Attribute = attribute;
     Policy    = policy;
 }
        public HandlerDescriptor(Type type)
        {
            foreach (var method in type.GetMethods(Binding))
            {
                MethodDispatch dispatch = null;

                if (method.IsSpecialName || method.IsFamily ||
                    method.DeclaringType == typeof(object))
                {
                    continue;
                }

                var attributes = (DefinitionAttribute[])
                                 Attribute.GetCustomAttributes(method, typeof(DefinitionAttribute), false);

                foreach (var attribute in attributes)
                {
                    var policy = attribute.CallbackPolicy;
                    var rule   = policy.MatchMethod(method, attribute);
                    if (rule == null)
                    {
                        throw new InvalidOperationException(
                                  $"The policy for {attribute.GetType().FullName} rejected method '{method.GetDescription()}'");
                    }

                    dispatch = dispatch ?? new MethodDispatch(method);
                    var binding = rule.Bind(dispatch, attribute);

                    if (_methods == null)
                    {
                        _methods = new Dictionary <CallbackPolicy, PolicyMethods>();
                    }

                    PolicyMethods methods;
                    if (!_methods.TryGetValue(policy, out methods))
                    {
                        methods = new PolicyMethods();
                        _methods.Add(policy, methods);
                    }

                    methods.Insert(binding);
                }
            }
        }
示例#7
0
 public HandleMethodBinding(MethodDispatch dispatch)
     : base(dispatch)
 {
 }
示例#8
0
 public virtual PolicyMethodBinding BindMethod(MethodRule rule,
                                               MethodDispatch dispatch, DefinitionAttribute attribute)
 {
     return(Binder?.Invoke(rule, dispatch, attribute, this)
            ?? new PolicyMethodBinding(rule, dispatch, attribute, this));
 }