ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ramon Casha" <ramon.ca...@megabyte.net>
Subject Feature request + patch
Date Thu, 11 Aug 2005 11:37:44 GMT
I altered my copy of iBATIS.NET so as to allow a provider to mix classes from different assemblies.
In my case I needed it because I created a "wrapper class" around SqlCommand but wanted to
retain all the other classes as they were. The way it works now is that if a classname contains
a comma, it is loaded via "IBatisNet.Common.Utilities.Resources.TypeForName(className)" which
can load from different assemblies, while if it has no comma it is loaded as before.

If you think this is a good idea, here's a patch for Provider.cs:

START PATCH vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Index: Provider.cs
===================================================================
--- Provider.cs	(revision 2)
+++ Provider.cs	(working copy)
@@ -462,6 +462,15 @@
 		#endregion
 
 		#region Methods
+
+		private Type GetType(Assembly assembly, string className) {
+			if(className.IndexOf(',') >= 0) {
+				return IBatisNet.Common.Utilities.Resources.TypeForName(className);
+			} else {
+				return assembly.GetType(className, true);
+			}
+		}
+
 		/// <summary>
 		/// Init the provider.
 		/// </summary>
@@ -476,25 +485,25 @@
 				assembly = Assembly.Load(_assemblyName);
 
 				// Build the Command template 
-				type = assembly.GetType(_commandClass, true);
+				type = GetType(assembly,_commandClass);
 				_templateCommand = (IDbCommand)type.GetConstructor(Type.EmptyTypes).Invoke(null);
 				// Build the DataAdapter template 
-				type = assembly.GetType(_dataAdapterClass, true);
+				type = GetType(assembly,_dataAdapterClass);
 				_templateDataAdapter = (IDbDataAdapter)type.GetConstructor(Type.EmptyTypes).Invoke(null);
 				// Build the connection template 
-				type = assembly.GetType(_connectionClass, true);
+				type = GetType(assembly,_connectionClass);
 				_templateConnection = (IDbConnection)type.GetConstructor(Type.EmptyTypes).Invoke(null);
 				// Get the IDataParameter type
-				_dataParameterType = assembly.GetType(_dataParameter, true);
+				_dataParameterType = GetType(assembly,_dataParameter);
 				// Get the CommandBuilder Type
-				_commandBuilderType = assembly.GetType(_commandBuilderClass, true);
+				_commandBuilderType = GetType(assembly,_commandBuilderClass);
 				if (_parameterDbTypeClass.IndexOf(',')>0)
 				{
 					_parameterDbType = cachedTypeResolver.Resolve(_parameterDbTypeClass);
 				}
 				else
 				{
-					_parameterDbType = assembly.GetType(_parameterDbTypeClass, true);
+					_parameterDbType = GetType(assembly,_parameterDbTypeClass);
 				}
 
 				_templateConnectionIsICloneable = _templateConnection is ICloneable;
END PATCH ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
________________________________

Ramon Casha
Megabyte Ltd (www.megabyte.net <http://www.megabyte.net/> )
F4, The Technopark, Mosta MST02 Malta
tel: (+356) 2142 1600
fax: (+356) 2142 1590 	Megabyte Ltd <file:///C:/Documents%20and%20Settings/rac.MEGABYTE.000/My%20Documents/My%20Pictures/mb-email-signature.gif>
	

DISCLAIMER 
The information contained in this electronic mail may be confidential or legally privileged.
It is for the intended recipient(s) only. Should you receive this message in error, please
notify the sender by replying to this mail. Unauthorised use of the contents is strictly prohibited.
Whilst all care has been taken, the Megabyte Group is not responsible for the integrity of
the contents of this electronic mail and any attachments included within. 



Mime
View raw message