Esempio n. 1
0
 public void WriteData()
 {
     foreach (var method in Speaker.Tape.MethodCalls)
     {
         MethodDictionary[method.MethodName](method.Params);
     }
 }
Esempio n. 2
0
 protected MethodGenerator(NativeCompiler compiler, SmalltalkClass cls, MethodDictionary methods)
     : base(compiler)
 {
     if (cls == null)
     {
         throw new ArgumentNullException("cls");
     }
     if (methods == null)
     {
         throw new ArgumentNullException("methods");
     }
     this.Class   = cls;
     this.Methods = methods;
     this.LiteralEncodingStrategy         = new NativeLiteralEncodingStrategy(this);
     this.DynamicCallStrategy             = new NativeDynamicCallStrategy(this);
     this.DiscreteBindingEncodingStrategy = new NativeDiscreteBindingEncodingStrategy(this);
 }
Esempio n. 3
0
        public PluginCommandMethodReturnValue Shell(string commandContent)
        {
            var context    = PluginCommandMethod.Create(commandContent);
            var methodName = context.MethodName;
            var methodArgs = context.MethodArgs;

            if (MethodDictionary.ContainsKey(methodName))
            {
                var factory = MethodDictionary[methodName];
                var args    = factory.Create(methodArgs);
                var rtvalue = Dispatch(args);

                var result = new PluginCommandMethodReturnValue()
                {
                    PluginName        = InnerPluginName,
                    MethodName        = methodName,
                    MethodReturnValue = rtvalue,
                };
                return(result);
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Invokes a method represented by a specified <see cref="MethodInfo"/>, using
        /// the specified parameters.
        /// </summary>
        /// <param name="methodInfo">
        /// The method representation.
        /// </param>
        /// <param name="instance">
        /// The object on which to invoke the method. If the method is static, this
        /// value is ignored.
        /// </param>
        /// <param name="arguments">
        /// An argument list for the invoked method. This is an array of objects
        /// with the same number, order, and type as the parameters of the method
        /// to be invoked. If there are no parameters, parameters should be null.
        /// Ref/out parameters are not supported.
        /// </param>
        /// <returns>
        /// The return value from the method, or null for methods that return void.
        /// </returns>
        public static object InvokeEnhanced(this MethodInfo methodInfo, object instance, object[] arguments)
        {
            //just good practice
            if (methodInfo == null)
            {
                ThrowArgumentNull(nameof(methodInfo));
            }
            //the following check is more descriptive than the NullReferenceException that would otherwise occur
            // ReSharper disable once PossibleNullReferenceException
            if (!methodInfo.IsStatic && instance == null)
            {
                ThrowArgumentNull(nameof(instance), "Instance is required for non static methods");
            }
            //the lambda ignores extra arguments so the following check is necessary
            if (methodInfo.GetParameters().Length != (arguments?.Length ?? 0))
            {
                ThrowArgument("Invalid number of arguments for this method", nameof(arguments));
            }
            //type errors will be thrown as InvalidCastException inside the lambda

            var lambda = MethodDictionary.GetOrAdd(methodInfo, InvokeEnhancedUncachedMethod);

            return(lambda(instance, arguments));
        }
 private ClassMethodGenerator(NativeCompiler compiler, SmalltalkClass cls, MethodDictionary methods)
     : base(compiler, cls, methods)
 {
 }
Esempio n. 6
0
 public MethodDictionary(IntermediateFullMemberDictionary master, TInstanceIntermediateType parent, MethodDictionary root)
     : base(master, parent, root)
 {
 }