Method's property

  • Thread starter Thread starter Nime
  • Start date Start date
N

Nime

For SQL queries, I want to use a code something like below:

SqlQuery query = new SqlQuery();
if(query("SELECT TOP 1 value FROM table").Error == 0) {value = query.Result;} else value = 0;

//Here, I execute a method then assign a property, at the same time.



I created a simpe SQL query class and now I simply do that:

if(query.ExecuteError(sql) == 0) {value = query.Result;}
else { value = 0; error = query.Error;}


I wonder can I do that, simply run a method and assign an inner property:

error = query.Execute(sql).Error;
 
For SQL queries, I want to use a code something like below:

SqlQuery query = new SqlQuery();
if(query("SELECT TOP 1 value FROM table").Error == 0) {value = query.Result;} else value = 0;

//Here, I execute a method then assign a property, at the same time.

I created a simpe SQL query class and now I simply do that:

if(query.ExecuteError(sql) == 0) {value = query.Result;}
else { value = 0; error = query.Error;}

I wonder can I do that, simply run a method and assign an inner property:

error = query.Execute(sql).Error;

Hi,

I do not quite understand what is your question, but the above line
should be valid. Of course if you run it you will know for sure if it
works or not
 
I wrote a class which one contains Execute method and Result & Error properties.

query.Execute(sql);
result = query.Result;
error = query.Error;

I don't know how I can combine the method and properties so I can write like the line below:

error = query.Execute(sql).Error;
if(error ==0) result = query.Result;
 
Nime said:
I wrote a class which one contains Execute method and Result & Error properties.

query.Execute(sql);
result = query.Result;
error = query.Error;

I don't know how I can combine the method and properties so I can write like the line below:

error = query.Execute(sql).Error;
if(error ==0) result = query.Result;

Well, if you define Execute so that it returns itself, you could do this:

class SqlWrapper
{
SqlWrapper Execute( string sql )
{
... do stuff ...
return this;
}
...

but I'm not convinced that it is particularly idiomatic. If you really
like the functional style, perhaps you should go download F# from Microsoft
Research. It is a fully functional managed language that fits into Visual
Studio and gives you access to the full CLR.
 
Well, if you define Execute so that it returns itself, you could do this:

class SqlWrapper
{
SqlWrapper Execute( string sql )
{
... do stuff ...
return this;
}
...


You right, I did that, now I can extend the Execute method...
I also did combine SQL connection + error handling and
I use all in one class...

query = new SqlQuery();
query.Connection.ConnectionString = "blahblah";
if (query.Execute(txtQuery.Text).Exception != null)
errordetail = query.Exception.Message;

.... and so on...
 
Back
Top