c# - How to overload a method that has params object[] as parameter -
our database has primary key defined on every table existing of combined key short , int. therefore, using entity framework can try find element calling it's context.dbset<>.find(params object[] parameters)
method. in our code like:
public client findclient(short sqlid, int incid) { context db = new context(); client result = db.clients.find(sqlid, incid); return result; }
however, in our code using structs store key values. our struct follows:
public struct dbkey { private short _sqlid; private int _incid; public short sqlid { { return _sqlid; } } public int incid { { return _incid; } } public dbkey(short sqlid, int incid) { this._sqlid = sqlid; this._incid = incid; }
and has other comparing methods etc. able call dbset.find method this:
public client findclient(dbkey key) { context db = new context(); client result = db.clients.find(key); return result; }
to able wrote extension overload method:
public static partial class extensions { public static t find<t>(this dbset<t> dbset, dbkey key) t : class { return dbset.find(key.incid, key.sqlid); } }
intellisense tells find method overloaded, 1 version accepting dbkey key
parameter, , other, original method accepting params object[] parameters
. however, when running code, function call original method , never overloaded, since dbkey matches original parameters, resulting in exception. how can solve problem?
well, can rename, or call static extension directly:
public client findclient(dbkey key) { context db = new context(); client result = extensions.find(db.clients, key); return result; }
Comments
Post a Comment