Exemplo n.º 1
0
 /// <summary>
 /// Creates a new BindingTarget when the method binding has succeeded.
 /// </summary>
 internal BindingTarget(string name, int actualArgumentCount, MethodTarget target, NarrowingLevel level, RestrictionInfo restrictedArgs) {
     _name = name;
     _target = target;
     _restrictedArgs = restrictedArgs;
     _level = level;
     _actualArgs = actualArgumentCount;
 }
Exemplo n.º 2
0
        private readonly int _actualArgs;                                                 // gets the actual number of arguments provided

        /// <summary>
        /// Creates a new BindingTarget when the method binding has succeeded.
        /// </summary>
        internal BindingTarget(string name, int actualArgumentCount, MethodCandidate candidate, NarrowingLevel level, RestrictionInfo restrictedArgs) {
            _name = name;
            _candidate = candidate;
            _restrictedArgs = restrictedArgs;
            _level = level;
            _actualArgs = actualArgumentCount;
        }
Exemplo n.º 3
0
        internal OptimizingCallDelegate MakeDelegate(RestrictionInfo restrictionInfo) {
            MethodInfo mi = Method as MethodInfo;
            if (mi == null) {
                return null;
            }

            Type declType = mi.GetBaseDefinition().DeclaringType;
            if (declType != null &&
                declType.Assembly == typeof(string).Assembly &&
                declType.IsSubclassOf(typeof(MemberInfo))) {
                // members of reflection are off limits via reflection in partial trust
                return null;
            }

            if (_returnBuilder.CountOutParams > 0) {
                return null;
            }

            // if we have a non-visible method see if we can find a better method which
            // will call the same thing but is visible.  If this fails we still bind anyway - it's
            // the callers responsibility to filter out non-visible methods.
            mi = CompilerHelpers.TryGetCallableMethod(mi);

            Func<object[], object>[] builders = new Func<object[], object>[_argBuilders.Count];
            bool[] hasBeenUsed = new bool[restrictionInfo.Objects.Length];

            for (int i = 0; i < _argBuilders.Count; i++) {
                var builder = _argBuilders[i].ToDelegate(_resolver, restrictionInfo.Objects, hasBeenUsed);
                if (builder == null) {
                    return null;
                }

                builders[i] = builder;
            }

            if (_instanceBuilder != null && !(_instanceBuilder is NullArgBuilder)) {
                return new Caller(mi, builders, _instanceBuilder.ToDelegate(_resolver, restrictionInfo.Objects, hasBeenUsed)).CallWithInstance;
            } else {
                return new Caller(mi, builders, null).Call;
            }
        }