We have a data access library with such universal methods:
public List<T> Find<T>(
List<DataObject> conditions,
Boolean fuzzy = false,
String order = null,
Int32 limit = Int32.MaxValue,
T start = null) where T : DataObject, new()
{
...
}
public List<T> Find<T>(
DataObject condition,
Boolean fuzzy = false,
String order = null,
Int32 limit = Int32.MaxValue,
T start = null) where T : DataObject, new()
{
...
}
Now our business objects should be endowed with several methods Get(), such as:
public static MyClass Get(Guid id)
{
List<MyClass> possibles = Get(new MyClass() { Id = id });
if (possibles.Count == 1)
{
return possibles[0];
}
else
{
return null;
}
}
public static List<MyClass> Get(
MyClass condition,
Boolean fuzzy = false,
String order = null,
Int32 limit = Int32.MaxValue,
MyClass start = null)
{
using (QueryBuilder qb = ResourceFinder.GetQueryBuilder()) {
return qb.Find<MyClass>(condition, fuzzy, order, limit, start);
}
}
public static List<MyClass> Get(
List<MyClass> conditions,
Boolean fuzzy = false,
String order = null,
Int32 limit = Int32.MaxValue,
MyClass start = null)
{
using (QueryBuilder qb = ResourceFinder.GetQueryBuilder()) {
return qb.Find<MyClass>(conditions, fuzzy, order, limit, start);
}
}
Is there a shorter way to determine this higher level Get()s?
This will be a great place to use some pre-processing; but C # is missing. With a few exceptions, they are all the same except for the Type parameter. And the ultimate goal is to make these almost identical definitions less copy / paste / replace efforts, which admittedly is not much; it's just stupid.
: DataObject. , DataObject, , , - SQL-. , .
. " , ", " " " " .