Beispiel #1
0
 public static MethodBase[] GetMethodInfos(MemberInfo[] members)
 {
     return(ArrayUtils.ConvertAll <MemberInfo, MethodBase>(
                members,
                delegate(MemberInfo inp) { return (MethodBase)inp; }));
 }
Beispiel #2
0
        // TODO: This should be merged into CallSiteBinder.
        private static LambdaExpression /*!*/ Stitch <T>(Expression binding, LambdaSignature <T> signature, LabelTarget returnLabel) where T : class
        {
            Expression updLabel = Expression.Label(CallSiteBinder.UpdateLabel);

            var site    = Expression.Parameter(typeof(CallSite), "$site");
            var @params = ArrayUtils.Insert(site, signature.Parameters);

            Expression body;

            if (returnLabel != signature.ReturnLabel)
            {
                // TODO:
                // This allows the binder to produce a strongly typed binding expression that gets boxed
                // if the call site's return value is of type object.
                // The current implementation of CallSiteBinder is too strict as it requires the two types to be reference-assignable.

                var tmp = Expression.Parameter(typeof(object));
                body = Expression.Convert(
                    Expression.Block(new[] { tmp },
                                     binding,
                                     updLabel,
                                     Expression.Label(
                                         returnLabel,
                                         Expression.Condition(
                                             Expression.NotEqual(
                                                 Expression.Assign(
                                                     tmp,
                                                     Expression.Invoke(
                                                         Expression.Property(
                                                             Expression.Convert(site, typeof(CallSite <T>)),
                                                             typeof(CallSite <T>).GetProperty("Update")
                                                             ),
                                                         @params
                                                         )
                                                     ),
                                                 AstUtils.Constant(null)
                                                 ),
                                             Expression.Convert(tmp, returnLabel.Type),
                                             Expression.Default(returnLabel.Type)
                                             )
                                         )
                                     ),
                    typeof(object)
                    );
            }
            else
            {
                body = Expression.Block(
                    binding,
                    updLabel,
                    Expression.Label(
                        returnLabel,
                        Expression.Invoke(
                            Expression.Property(
                                Expression.Convert(site, typeof(CallSite <T>)),
                                typeof(CallSite <T>).GetProperty("Update")
                                ),
                            @params
                            )
                        )
                    );
            }

            return(Expression.Lambda <T>(
                       body,
                       "CallSite.Target",
                       true, // always compile the rules with tail call optimization
                       @params
                       ));
        }