static void Main(string[] args)
        {
            ConsoleColor old = Console.ForegroundColor;
            try{
                var props = new ConnectionProperties();
                using (var frm = new ConnectionDialog(props, true, Assembly.LoadFrom))
                {
                    var result = frm.ShowDialog();
                    if (result != System.Windows.Forms.DialogResult.OK)
                        return;
                }

                var cxi = new FakeConnection();
                new ConnectionPropertiesSerializer().Serialize(cxi.DriverData, props);

                var driver = new MongoDynamicDataContextDriver();

                List<Assembly> assemblies = props.AssemblyLocations.Select(Assembly.LoadFrom).ToList();
                var code = driver.GetStaticCodeFiles()
                    .Concat(new string[] {driver.GenerateDynamicCode(props, assemblies, "", "driver")});
                if(props.InitializationQuery != null)
                    code = code.Concat(new string[]{driver.GenerateCustomInitQuery(props.InitializationQuery, "driver")});

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("------------------------------------------------");
                foreach (string s in code)
                {
                    Console.WriteLine(s);
                    Console.WriteLine("------------------------------------------------");
                }
                Console.ForegroundColor = old;

                using (var frm = new SaveFileDialog())
                {
                    var result = frm.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        using (StreamWriter writer = new StreamWriter(frm.OpenFile()))
                        {
                            foreach (string s in code)
                            {
                                writer.WriteLine(s);
                                writer.WriteLine("---------------------------------------------------");
                            }

                            writer.Flush();
                        }

                    }
                }

            }catch(Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
            }
            finally{
                Console.ForegroundColor = old;
            }
        }
        /// <summary>
        /// LinqPad calls this to display the Connection Options dialog & generate the connection
        /// properties.
        /// </summary>
        /// <param name="cxInfo">the serialized connection properties.</param>
        /// <param name="isNewConnection">True if this is a brand new connection</param>
        /// <returns>true if the connection dialog completed successfully</returns>
        public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection)
        {
            ConnectionProperties props;
            if(isNewConnection)
            {
                props = new ConnectionProperties();
            }
            else
            {
                props = propsSerializer.Deserialize(cxInfo.DriverData);
            }

            using(var form = new ConnectionDialog(props, isNewConnection, LoadAssemblySafely))
            {
                var result = form.ShowDialog();

                if(result == System.Windows.Forms.DialogResult.OK)
                {
                    propsSerializer.Serialize(cxInfo.DriverData, props);
                    cxInfo.DisplayName = string.Format("{0} ({1})", props.SelectedDatabase, props.ConnectionString);
                    return true;
                }
            }

            return false;
        }