Is this an appropriate use of generics and C#'s dynamic data type? -
Is this an appropriate use of generics and C#'s dynamic data type? -
the problem i'm having thus, we're building info access layer using our existing orm (it's old 1 called gentle) thought of moving fluent nhibernate. there few queries have add together custom clauses sqlbuilder in our existing setup, instance when retrieving person objects might adding clause like:
"personid in (select personid orders ordervalue > " + ordervalue + " , ordername = " + ordername
the point beingness parameters beingness added straight in string rather parameterised query, possible in gentle add together parameterised query , i've been working on. our dals inherit base of operations gentledal
, class constructs gentle query, adds clauses , parameters etc. add together parameterised clause in gentle have 2 things sqlbuilder object, have phone call sb.addconstraint(string clause)
add together clause, , each parameter have phone call sb.addparameter(string name, type type)
, can build sqlstatement
object this, , after can set value parameter phone call stmt.setparameter(string name, object value)
.
the way have represented these parameters/clauses have created class called gentleclausecollection, contains clauses , parameters , has add together , methods both of these things. clauses strings , stored internally in list, parameters stored in gentleparameter class uses generics. total code gentleparameter follows.
public class gentleparameter<tparamtype> { public string name { get; private set; } public tparamtype value { get; private set; } public type parametertype {get { homecoming typeof (tparamtype); }} public gentleparameter(string parametername, tparamtype parametervalue) { name = parametername; value = parametervalue; } }
there no collection in .net i'm aware of allow me store gentleparameter different values of tparamtype in same collection, can done using dlr. in gentlecollection class store parameters in list , parameters class ienumerable. add together method in class able allow gentleparameter's added know parameters have name, value , parametertype field can access.
my questions are: given sacrifice generics , alter parameter class value property 'object' instead of t, have overcomplicated things using dynamic, pros , cons of both approaches? there 3rd way haven't thought of , how important performance impact see using dynamic given method calls using dynamic objects compiled @ run time?
thanks in advance help.
as sb.setparameter
not generic , awaits object
, not create gentleparameter
generic , hence not utilize dlr.
c# generics c#-4.0 dynamic data-access-layer
Comments
Post a Comment