BACKGROUND: In the API I am porting, there are a large number of functions prefixed with sqlite3_. They are encapsulated in a class named Sqlite3, so the function call is Sqlite3.sqlite3_…
I’ve created a number of alias calls, similar to the following,
//C# alias for call
public static void result_error_toobig(sqlite3_context pCtx)
{ sqlite3_result_error_toobig(pCtx); }
//Native call
public static void sqlite3_result_error_toobig(sqlite3_context pCtx)
{
Debug.Assert(sqlite3_mutex_held(pCtx.s.db.mutex));
pCtx.isError = SQLITE_ERROR;
setResultStrOrError(pCtx, "string or blob too big", -1,
SQLITE_UTF8, SQLITE_STATIC);
}
This allows me to write code, like Sqlite3.result_error_toobig(pCtx);
QUESTION:
- Will the compiler optimize the call, so the overhead is minimal?
- Is there an easier way to create this type of alias?
One time saver you could employ is using public delegate fields rather than creating methods for each function. As long as the parameter signatures are the same, you could do something like this:
Edit:
If you need to pass parameters by reference, you probably can’t use those convenient
ActionandFuncclasses. However, you can declare your own delegate types, like this:Then, in your static
Sqlite3class, you could do something like this: