I am getting three "Suggestions" IDE0017 Object Initialization cab be simplified.
private string dbSelect()
{
// This is the User File Name Selection
OpenFileDialog openThis = new OpenFileDialog();
openThis.DefaultExt = "sqlite";
openThis.Filter = "SQLite Databases|*.sqlite";
if (openThis.ShowDialog() == DialogResult.OK)
{
return openThis.FileName;
}
return null;
}
public bool openDatabase()
{
OpenFileDialog openThis = new OpenFileDialog();
openThis.DefaultExt = "sqlite";
openThis.Filter = "SQLite Databases|*.sqlite";
if (openThis.ShowDialog() == DialogResult.OK)
{
m_dbConnection = new SQLiteConnection("Data Source=" + openThis.FileName + ";Version=3;");
m_dbConnection.Open();
return true;
}
return false;
}
public bool createDatabase()
{
SaveFileDialog createThis = new SaveFileDialog();
createThis.DefaultExt = "sqlite";
createThis.Filter = "SQLite Databases|*.sqlite";
if (createThis.ShowDialog() != DialogResult.OK || createThis.FileName.Trim() == "")
{
return false;
}
m_dbConnection = new SQLiteConnection("Data Source=" + createThis.FileName + ";Version=3;");
m_dbConnection.Open();
return true;
}
How do I reform these to simplify them? They've been fine until VS2017...
And, so far, Google hasn't really helped.
And, I am not sure I like the idea that simplification means placing everything in a single line.
I was taught that readability is important and all in one line is just plain cluttered.
But, I'd hate to miss a trick... I suppose I can just turn it off...
Uppon creating a new instance of anything instead of doing
MyType myVariable = new MyType();
and then set every property frommyVariable
line by line you can doMyType myVariable = new MyType() {};
and between the{}
you can set the properties you want to set.For the
SaveFileDialog
for example you can do :