我有一个问题,我无法自己解决。我是新来编程,我将不胜感激,如果你能帮助我解决这个问题:
我有一个类,我想继承:如何在C#中将对象从一个类调用到另一个类#
namespace rsDeployer.Common.SQLServerCommunication
{
public class RSDatabaseConnectionCreator: LoggerBase
{
public RSProfile profile;
public RSDatabaseConnectionCreator(RSProfile profile)
{
this.profile = profile;
}
public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false)
{
var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication);
if (testConnection)
{
return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null;
}
return new SqlConnection(connectionString);
}
}
}
,我想调用的CreateConnection()在另一类注入方法让我打开连接,然后执行脚本。
编辑1级我想注入它。
public void QueryExecution(string SQLQuery)
{
//here's where I would like to inject it
SqlCommand command = new SqlCommand(SQLQuery, conn);
var file = new StreamWriter(@"D:\Project\rsDeployer\ImportedQuery.txt");
file.WriteLine(command);
file.Close();
}
如果这个问题是愚蠢的,应该得到答案你会指出我应该阅读的方向吗?
我希望这个问题能够很好地被问到和清楚。 在此先感谢。
你应该寻找一个对象的创建实例。 – Berkay
你能告诉你如何期待使用它吗?消费者级别是什么样子。 – Juan