|
Hi, I’m using Aspect# to proxy
Business Objects for various purposes; one of which is object state
tracking. It’s great that IBatis could instantiate by business
object proxy but not without some a little issue. Well, you could call it
a feature request. // I need IBatisNet to do something
like this public T Retrieve<T>(object
parameterObject) { return
SqlMapper.QueryForObject(“SomeStatement”, parameter,
ProxyManager.CreateInstance(typeof(T)); } Account c =
Retrieve<Account>(parameterObject); Issue:
Proxy object can contain multiple same name properties (aspect weaving) that
causes Ibatis property cache to throw an exception at:
ReflectionInfo.AddPropertiess(Type type)
PropertyInfo[] properties = type.GetProperties(BINDING_FLAGS_SET);
for (int i = 0; i < properties.Length; i++)
{
string name = properties[i].Name;
_setProperties.Add(name, properties[i]);
_setTypes.Add(name, properties[i].PropertyType);
} … Example: public class
Account {
public virtual double Balance { get; set; } } Account a = new
Account(); a.GetPropertyes()
– Balance (type: Account) Account b =
ProxyFactory.CreateInstance(typeof(Account)); B.GetProperties()
– [0] Balance (type: Account), [1] Balance (type:
CProxyAccount_IPersistable…)
The code
error at “_setProperties.Add(name, properties[i])” : Exception ~
key already exist.
Added:
In order to support Proxy object mapping, I commented out line 312 – 315
in ResultMap.cs:
/*if ( target.GetType() != _class )
{
throw new ArgumentException( "Could not set value of type '"+
target.GetType() +"' in property '"+property.PropertyName+"' of
type '"+_class+"'" );
}*/
In order to
overcome the issue I changed ReflectionInfo.AddProperties to:
PropertyInfo[] properties = type.GetProperties(BINDING_FLAGS_SET);
for (int i = 0; i < properties.Length; i++)
{
string name = properties[i].Name;
if (_setProperties.ContainsKey(name))
{
// determine if this is the better key
if (properties[i].DeclaringType.Equals(type))
{
_setProperties.Remove(name);
_setTypes.Remove(name);
}
else
continue;
}
_setProperties.Add(name, properties[i]);
_setTypes.Add(name, properties[i].PropertyType);
}…
This requires local build of DataMapper and keeps track of changes.
Request:
Also, I would like something similar for QueryForList…
SqlMapper.QueryForList(“SomeStatement”, parameter,
dummyValueObject, list) where the IBatisNet use dummyObject type (proxy type)
as object type to add to list…
I.E:
IList<Account> lst = new List<Account>();
SqlMapper.QueryForList(“SomeStatement”, parameter,
ProxyManager.CreateInstance(typeof(Account)), lst);
return lst; Thanks, Tom Nguyen |

