Exemple #1
0
        /// <summary>
        /// Produces a rule for the specified Action for the given arguments.
        ///
        /// The default implementation can produce rules for standard .NET types.  Languages should
        /// override this and provide any custom behavior they need and fallback to the default
        /// implementation if no custom behavior is required.
        /// </summary>
        /// <typeparam name="T">The type of the DynamicSite the rule is being produced for.</typeparam>
        /// <param name="action">The Action that is being performed.</param>
        /// <param name="args">The arguments to the action as provided from the call site at runtime.</param>
        /// <param name="callerContext">The CodeContext that is requesting the rule and should be use</param>
        /// <returns></returns>
        protected virtual StandardRule <T> MakeRule <T>(CodeContext /*!*/ callerContext, DynamicAction /*!*/ action, object[] /*!*/ args)
        {
            Contract.RequiresNotNull(callerContext, "callerContext");
            Contract.RequiresNotNull(action, "action");
            Contract.RequiresNotNull(args, "args");

            switch (action.Kind)
            {
            case DynamicActionKind.Call:
                return(new CallBinderHelper <T, CallAction>(callerContext, (CallAction)action, args).MakeRule());

            case DynamicActionKind.GetMember:
                return(new GetMemberBinderHelper <T>(callerContext, (GetMemberAction)action, args).MakeNewRule());

            case DynamicActionKind.SetMember:
                return(new SetMemberBinderHelper <T>(callerContext, (SetMemberAction)action, args).MakeNewRule());

            case DynamicActionKind.CreateInstance:
                return(new CreateInstanceBinderHelper <T>(callerContext, (CreateInstanceAction)action, args).MakeRule());

            case DynamicActionKind.DoOperation:
                return(new DoOperationBinderHelper <T>(callerContext, (DoOperationAction)action, args).MakeRule());

            case DynamicActionKind.DeleteMember:
                return(new DeleteMemberBinderHelper <T>(callerContext, (DeleteMemberAction)action, args).MakeRule());

            case DynamicActionKind.InvokeMember:
                return(new InvokeMemberBinderHelper <T>(callerContext, (InvokeMemberAction)action, args).MakeRule());

            case DynamicActionKind.ConvertTo:
                return(new ConvertToBinderHelper <T>(callerContext, (ConvertToAction)action, args).MakeRule());

            default:
                throw new NotImplementedException(action.ToString());
            }
        }
Exemple #2
0
 private static void NoteRuleCreation(DynamicAction action, object[] args)
 {
     PerfTrack.NoteEvent(PerfTrack.Categories.Rules, "MakeRule " + action.ToString() + " " + CompilerHelpers.GetType(args[0]).Name);
 }