Exemplo n.º 1
0
        protected override void InitializeFromMethod(MethodBase method)
        {
            if (!method.IsStatic)
            {
                throw new ArgumentException("Remote executor supports only static methods.", "method");
            }

            var parameters = method.GetParameters();
            this.serializeParameters = new bool[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                var parameterType = parameters[i].ParameterType;

                // TODO: it is not going to work with structs
                if (parameterType.IsClass)
                {
                    if (!parameterType.IsSerializable)
                    {
                        throw new ArgumentException(
                            string.Format("Remote executor supports only serializable classes as method parameters[{0}]. Consider adding [Serializable] attribute.", parameterType.FullName),
                            "method");
                    }

                    this.serializeParameters[i] = true;
                }
            }

            var methodInfo = method as MethodInfo;
            if (methodInfo != null)
            {
                var returnType = methodInfo.ReturnType;
                if (returnType.IsClass)
                {
                    if (!returnType.IsSerializable)
                    {
                        throw new ArgumentException(
                            string.Format("Remote executor supports only serializable classes as method result[{0}]. Consider adding [Serializable] attribute.", returnType.FullName),
                            "method");
                    }

                    this.serializeResult = true;
                }
            }

            var methodHandle = method.SerializeMethodHandle();

            Log.TraceMessage(Log.Activity.Calling_initialize_on_remote_executor, string.Format("Calling initialize on remote executor. Method handle: '{0}'.", methodHandle.ToReadableString()));

            this.Eid = this.Client.Initialize(methodHandle);
        }