T
tomjbr.32022025
I have started looking at the nhibernate framework, but do not really
like the string based API which makes it impossible to use automatic
refactoring of a property name without the risk of getting problems
where the property has been refered to as a string...
Therefore I am wondering if it would be even theoretically possible to
improve such a framework with stronger typing, to avoid the usage of
strings.
For example, consider this code example from the NHibernate framework:
IList cats = sess.CreateCriteria(typeof(Cat)).AddOrder(
Order.Asc("Name") ).List();
Here is what I wish could be done instead:
IList cats = sess.CreateCriteria(typeof(Cat)).AddOrder(
Order.Asc(Cat.Name) ).List();
Obviously the above kind of syntax would not even compile unless there
would be a static "Name" property in the Cat class, but perhaps
something like this might be possible:
Cat aCat = new Cat();
IList cats = sess.CreateCriteria(typeof(Cat)).AddOrder(
Order.Asc(aCat.Name) ).List();
But the question is whether it would be at all possible to implement
the "Order.Asc" method
so that its formal parameter could be used to retrieve the string
"Name" from the actual parameter in the invocation ?
/ Tomas
like the string based API which makes it impossible to use automatic
refactoring of a property name without the risk of getting problems
where the property has been refered to as a string...
Therefore I am wondering if it would be even theoretically possible to
improve such a framework with stronger typing, to avoid the usage of
strings.
For example, consider this code example from the NHibernate framework:
IList cats = sess.CreateCriteria(typeof(Cat)).AddOrder(
Order.Asc("Name") ).List();
Here is what I wish could be done instead:
IList cats = sess.CreateCriteria(typeof(Cat)).AddOrder(
Order.Asc(Cat.Name) ).List();
Obviously the above kind of syntax would not even compile unless there
would be a static "Name" property in the Cat class, but perhaps
something like this might be possible:
Cat aCat = new Cat();
IList cats = sess.CreateCriteria(typeof(Cat)).AddOrder(
Order.Asc(aCat.Name) ).List();
But the question is whether it would be at all possible to implement
the "Order.Asc" method
so that its formal parameter could be used to retrieve the string
"Name" from the actual parameter in the invocation ?
/ Tomas