便携式类库中的反思

时间:2015-05-06 17:03:04

标签: reflection portable-class-library

我想在便携式类库中动态加载dll。代码等同于下面发布的代码。 " AssemblyName.GetAssemblyName"似乎在可移植类库中不支持。我需要一个等效的代码,根据名称和路径加载程序集。我不知道编译时程序集的名称。

        static string DATABASENAME = "adora";
        static string SEVERNAME = "localhost";
        static string CONNECTIONSTRING = "Server=" + SEVERNAME +";Database="+ DATABASENAME + ";Trusted_Connection=True;";

 public void RestoreDatabase(String filePath, String dataFilePath, String logFilePath)
        {
            Restore sqlRestore = new Restore();

            BackupDeviceItem deviceItem = new BackupDeviceItem(filePath, DeviceType.File);
            sqlRestore.Devices.Add(deviceItem);
            sqlRestore.Database = DATABASENAMERE;

            using (SqlConnection connectionx = new SqlConnection(CONNECTIONSTRINGRE))
            {
                connectionx.Open();
                // Do work here; connection closed on following line.
                ServerConnection connection = new ServerConnection(connectionx);
                Server sqlServer = new Server(connection);

                Database db = sqlServer.Databases[DATABASENAMERE];
                sqlRestore.Action = RestoreActionType.Database;
                String dataFileLocation = dataFilePath + DATABASENAMERE + ".mdf";
                String logFileLocation = logFilePath + DATABASENAMERE + "_Log.ldf";
                db = sqlServer.Databases[DATABASENAMERE];
                RelocateFile rf = new RelocateFile(DATABASENAMERE, dataFileLocation);

                sqlRestore.RelocateFiles.Add(new RelocateFile(DATABASENAMERE, dataFileLocation));
                sqlRestore.RelocateFiles.Add(new RelocateFile(DATABASENAMERE + "_log", logFileLocation));
                sqlRestore.ReplaceDatabase = true;
                //sqlRestore.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
                sqlRestore.PercentCompleteNotification = 10;
               // sqlRestore.PercentComplete += new PercentCompleteEventHandler(sqlRestore_PercentComplete);

                sqlRestore.SqlRestore(sqlServer);
                db = sqlServer.Databases[DATABASENAMERE];
                db.SetOnline();

                sqlServer.Refresh();

            }
        }

0 个答案:

没有答案