Avatar
11977 reputation
Posted on:12 Sep '16 - 10:37
1

Overriding new SqlParameter

I need to check the value of the SqlParameter object and change it based on special labels.ie: [BB] ==> Baseball, [FP] ==> Fastpitch.

I can do it with an additional function like this:

_params.Add(new SqlParameter(@Change, paramCheck(obj.Change)));
I would like to try overriding the new SqlParameter method/function and run my check in there. How can I do that?

Answers

3
This answer is accepted

Well, you can't literally override new SqlParameter because SqlParameter is sealed, but you can create a function that returns a new SqlParameter:

public SqlParameter NewSqlParameter(string name, object value) 
{
    return new SqlParameter(name, paramCheck(value));
}
and call it as such:

_params.Add(NewSqlParameter("@Change", obj.Change));

Avatar
7979 reputation
Posted on:13 Sep '16 - 12:37

Please login in order to answer a question