public static byte[] GetBytes(this MailMessage mailMessage)
        {
            Assembly assembly        = typeof(SmtpClient).Assembly;
            Type     type            = assembly.GetType("System.Net.Mail.MailWriter");
            var      parametersTypes = new[]
            {
                typeof(Stream)
            };
            object x = null;

            using (Stream stream = new MemoryStream())
            {
                var constructorInfo = type.GetConstructor
                                      (
                    BindingFlags.Instance | BindingFlags.NonPublic
                    , null
                    , parametersTypes
                    , null
                                      );
                var func = DynamicCallMethodExpressionTreeInvokerHelper.CreateNewInstanceConstructorInvokerFunc <object>
                           (
                    type
                    , constructorInfo
                           );
                x = func(new[] { stream });
                var action = DynamicCallMethodExpressionTreeInvokerHelper.CreateMethodCallInvokerAction <MailMessage>
                             (
                    typeof(MailMessage)
                    , () =>
                {
                    var methodInfo = typeof(MailMessage).GetMethod
                                     (
                        "Send"
                        , BindingFlags.NonPublic | BindingFlags.Instance
                        , null
                        , new[] { type, typeof(bool) }
                        , null
                                     );
                    return(methodInfo);
                }
                             );
                action
                (
                    mailMessage
                    , new[]
                {
                    x
                    , true
                }
                );
                byte[] buffer = StreamDataHelper.ReadDataToBytes(stream);
                return(buffer);
            }
        }
        static JScriptEvaluator()
        {
            CodeDomProvider    provider = CodeDomProvider.CreateProvider("JScript");
            CompilerParameters parameters;

            parameters = new CompilerParameters();
            parameters.GenerateInMemory = true;
            CompilerResults results;

            results = provider.CompileAssemblyFromSource(parameters, _JScript);
            Assembly assembly = results.CompiledAssembly;

            _evaluatorType = assembly.GetType("Microshaoft.JScriptEvaluator");
            var constructorInfo = _evaluatorType.GetConstructors().First();
            var func            = DynamicCallMethodExpressionTreeInvokerHelper.CreateNewInstanceConstructorInvokerFunc
                                  (
                _evaluatorType
                , constructorInfo
                                  );

            _evaluator = func(null);
            //_evaluator = Activator.CreateInstance(_evaluatorType);
        }
        public static string ComputeFormula <TParameter>(string formula, params TParameter[] parameters)
        {
            object[] objects = new object[parameters.Length];
            Array.Copy(parameters, objects, objects.Length);
            string expression1 = string.Format(formula, objects);

            //return (string)JScriptEvaluator.Eval(expression1);
            //=====================================================================
            object[] ps = new object[parameters.Length];
            Array.Copy(parameters, 0, ps, 0, ps.Length);
            if (_func == null)
            {
                _func = DynamicCallMethodExpressionTreeInvokerHelper.CreateMethodCallInvokerFunc <string, string>
                        (
                    typeof(string)
                    , () =>
                {
                    var methodsInfos = typeof(string).GetMethods();
                    var methodInfo   = methodsInfos.First
                                       (
                        (x) =>
                    {
                        var parametersInfos = x.GetParameters();
                        //Debug.Assert(x.Name.ToLower() == "Format".ToLower());
                        return
                        (x.Name.ToLower() == "Format".ToLower() &&
                         x.IsStatic &&
                         parametersInfos[0].ParameterType == typeof(string) &&
                         parametersInfos[1].ParameterType == typeof(object[]) &&
                         Attribute.IsDefined
                         (
                             parametersInfos[1]
                             , typeof(ParamArrayAttribute)
                         ));
                    }
                                       );
                    return(methodInfo);
                }
                        );
            }
            string expression = (string)_mi.Invoke
                                (
                null
                , new object[]
            {
                formula
                , ps
            }
                                );

            expression = (string)_func
                         (
                formula
                , new object[]
            {
                formula
                , ps
            }
                         );
            return((string)JScriptEvaluator.Eval(expression));
        }