Author: gbayon
Date: Sun Apr  9 11:24:53 2006
New Revision: 392799

URL: http://svn.apache.org/viewcvs?rev=392799&view=rev
Log:
- refactoring IObjectFactory and IFactory to allow future constructor mapping 
in ResultMap

Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ObjectFactoryTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorFactory.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorObjectFactory.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IFactory.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IObjectFactory.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/EmitPropertyAccessor.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs Sun Apr  9 
11:24:53 2006
@@ -13,6 +13,53 @@
         private string _lastName = string.Empty;
         private string _emailAddress = string.Empty;
                private int[] _ids = null;
+               private string _test = string.Empty;
+               private Days _days ;
+               private Property _prop = null ;
+
+               public Account()
+               {}
+
+               public Account(int id)
+               {
+                       _id = id;
+               }
+
+               public Account(string test)
+               {
+                       _test = test;
+               }
+
+               public Account(Days days)
+               {
+                       _days = days;
+               }
+
+               public Account(Property prop)
+               {
+                       _prop = prop;
+               }
+
+               public Account(string firstName, Property prop)
+               {
+                       _firstName = firstName;
+                       _prop = prop;
+               }
+
+               public Property Property
+               {
+                       get { return _prop; }
+               }
+
+               public Days Days
+               {
+                       get { return _days; }
+               }
+
+               public string Test
+               {
+                       get { return _test; }
+               }
 
                public int Id
                {

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs Sun Apr  9 
11:24:53 2006
@@ -2,15 +2,15 @@
 
 namespace IBatisNet.Common.Test.Domain
 {
-    public enum Days
+    public enum Days : int
     {
         Sat = 1,
-        Sun,
-        Mon,
-        Tue,
-        Wed,
-        Thu,
-        Fri
+        Sun = 2,
+        Mon = 3,
+        Tue = 4,
+        Wed = 5,
+        Thu = 6,
+        Fri = 7
     };
 
        /// <summary>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ObjectFactoryTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ObjectFactoryTest.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ObjectFactoryTest.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ObjectFactoryTest.cs
 Sun Apr  9 11:24:53 2006
@@ -11,20 +11,131 @@
        {
 
                [Test]
+               public void DynamicFactoryWithConstructor0()
+               {
+                       IObjectFactory objectFactory = new ObjectFactory(true);
+
+                       Type[] types = {typeof(string)};
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
+
+                       object[] parameters = {"gilles"};
+                       object obj = factory.CreateInstance(parameters);
+
+                       Assert.IsTrue(obj is Account);
+                       Account account = (Account)obj;
+                       Assert.AreEqual("gilles", account.Test);
+               }
+
+               [Test]
+               public void DynamicFactoryWithConstructor1()
+               {
+                       IObjectFactory objectFactory = new ObjectFactory(true);
+
+                       Type[] types = {typeof(string)};
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
+
+                       object[] parameters = new object[1];
+                       parameters[0] = null;
+                       object obj = factory.CreateInstance(parameters);
+
+                       Assert.IsTrue(obj is Account);
+                       Account account = (Account)obj;
+                       Assert.AreEqual(null, account.Test);
+               }
+
+               [Test]
+               public void DynamicFactoryWithConstructor2()
+               {
+                       IObjectFactory objectFactory = new ObjectFactory(true);
+
+                       Type[] types = {typeof(int)};
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
+
+                       object[] parameters = new object[1];
+                       parameters[0] = -55;
+                       object obj = factory.CreateInstance(parameters);
+
+                       Assert.IsTrue(obj is Account);
+                       Account account = (Account)obj;
+                       Assert.AreEqual( -55, account.Id);
+               }
+
+               [Test]
+               public void DynamicFactoryWithConstructor3()
+               {
+                       IObjectFactory objectFactory = new ObjectFactory(true);
+
+                       Type[] types = {typeof(Days)};
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
+
+                       object[] parameters = new object[1];
+                       parameters[0] = Days.Sun;
+                       object obj = factory.CreateInstance(parameters);
+
+                       Assert.IsTrue(obj is Account);
+                       Account account = (Account)obj;
+                       Assert.AreEqual( Days.Sun, account.Days);
+               }
+
+               [Test]
+               public void DynamicFactoryWithConstructor4()
+               {
+                       IObjectFactory objectFactory = new ObjectFactory(true);
+
+                       Type[] types = {typeof(Property)};
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
+
+                       object[] parameters = new object[1];
+                       Property prop = new Property();
+                       prop.String = "Gilles";
+                       parameters[0] = prop;
+                       object obj = factory.CreateInstance(parameters);
+
+                       Assert.IsTrue(obj is Account);
+                       Account account = (Account)obj;
+                       Assert.IsNotNull(account.Property);
+                       Assert.AreEqual( "Gilles", account.Property.String);
+               }
+
+               [Test]
+               public void DynamicFactoryWithConstructor5()
+               {
+                       IObjectFactory objectFactory = new ObjectFactory(true);
+
+                       Type[] types = {typeof(string), typeof(Property)};
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
+
+                       object[] parameters = new object[2];
+                       Property prop = new Property();
+                       prop.String = "Gilles";
+                       parameters[0] = "Héloïse";
+                       parameters[1] = prop;
+                       object obj = factory.CreateInstance(parameters);
+
+                       Assert.IsTrue(obj is Account);
+                       Account account = (Account)obj;
+                       Assert.AreEqual("Héloïse", account.FirstName);
+                       Assert.IsNotNull(account.Property);
+                       Assert.AreEqual( "Gilles", account.Property.String);
+               }
+
+
+
+               [Test]
                public void DynamicFactoryCreatesTypes()
                {
                        IObjectFactory objectFactory = new ObjectFactory(true);
 
-                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account));
-                       object obj = factory.CreateInstance();
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), Type.EmptyTypes);
+                       object obj = factory.CreateInstance(null);
                        Assert.IsTrue(obj is Account);
 
-                       factory = objectFactory.CreateFactory(typeof (Account));
-                       obj = factory.CreateInstance();
+                       factory = objectFactory.CreateFactory(typeof (Account), 
Type.EmptyTypes);
+                       obj = factory.CreateInstance(Type.EmptyTypes);
                        Assert.IsTrue(obj is Account);
 
-                       factory = objectFactory.CreateFactory(typeof (Simple));
-                       obj = factory.CreateInstance();
+                       factory = objectFactory.CreateFactory(typeof (Simple), 
Type.EmptyTypes);
+                       obj = factory.CreateInstance(Type.EmptyTypes);
                        Assert.IsTrue(obj is Simple);
                }
 
@@ -39,7 +150,7 @@
 
                        // create an instance so that Activators can
                        // cache the type/constructor/whatever
-                       factory.CreateInstance();
+                       factory.CreateInstance(Type.EmptyTypes);
 
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
@@ -48,18 +159,18 @@
                        timer.Start();
                        for (int i = 0; i < TEST_ITERATIONS; i++)
                        {
-                               factory.CreateInstance();
+                               factory.CreateInstance(Type.EmptyTypes);
                        }
                        timer.Stop();
                        double newFactoryResult = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
                        #endregion
 
                        #region activator
-                       factory = new 
ActivatorObjectFactory().CreateFactory(typeof(Account));
+                       factory = new 
ActivatorObjectFactory().CreateFactory(typeof(Account), Type.EmptyTypes);
 
                        // create an instance so that Activators can
                        // cache the type/constructor/whatever
-                       factory.CreateInstance();
+                       factory.CreateInstance(Type.EmptyTypes);
 
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
@@ -67,18 +178,18 @@
                        timer.Start();
                        for (int i = 0; i < TEST_ITERATIONS; i++)
                        {
-                               factory.CreateInstance();
+                               factory.CreateInstance(Type.EmptyTypes);
                        }
                        timer.Stop();
                        double activatorFactoryResult = 1000000 * 
(timer.Duration / (double)TEST_ITERATIONS);
                        #endregion
 
                        #region Emit
-                       factory = new 
EmitObjectFactory().CreateFactory(typeof(Account));
+                       factory = new 
EmitObjectFactory().CreateFactory(typeof(Account), Type.EmptyTypes);
 
                        // create an instance so that Activators can
                        // cache the type/constructor/whatever
-                       factory.CreateInstance();
+                       factory.CreateInstance(Type.EmptyTypes);
 
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
@@ -86,7 +197,7 @@
                        timer.Start();
                        for (int i = 0; i < TEST_ITERATIONS; i++)
                        {
-                               factory.CreateInstance();
+                               factory.CreateInstance(Type.EmptyTypes);
                        }
                        timer.Stop();
                        double emitFactoryResult = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
@@ -103,10 +214,11 @@
 
                internal class NewAccountFactory : IFactory
                {
-                       public object CreateInstance()
+                       public object CreateInstance(object[] parameters)
                        {
                                return new Account();
                        }
+
                }
 
        }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorFactory.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorFactory.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorFactory.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorFactory.cs 
Sun Apr  9 11:24:53 2006
@@ -44,14 +44,32 @@
                }
 
                #region IFactory members
+//
+//             /// <summary>
+//             /// Create a new object instance via via 
Activator.CreateInstance
+//             /// </summary>
+//             /// <returns>A new instance</returns>
+//             public object CreateInstance()
+//             {
+//                     return Activator.CreateInstance( _typeToCreate );
+//             }
 
+               
                /// <summary>
-               /// Create a new object instance via via 
Activator.CreateInstance
+               /// Create a new instance with the specified parameters
                /// </summary>
-               /// <returns></returns>
-               public object CreateInstance()
+               /// <param name="parameters">
+               /// An array of values that matches the number, order and type 
+               /// of the parameters for this constructor. 
+               /// </param>
+               /// <remarks>
+               /// If you call a constructor with no parameters, pass null. 
+               /// Anyway, what you pass will be ignore.
+               /// </remarks>
+               /// <returns>A new instance</returns>
+               public object CreateInstance(object[] parameters)
                {
-                       return Activator.CreateInstance( _typeToCreate );
+                       return Activator.CreateInstance( _typeToCreate, 
parameters );
                }
 
                #endregion

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorObjectFactory.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorObjectFactory.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorObjectFactory.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ActivatorObjectFactory.cs
 Sun Apr  9 11:24:53 2006
@@ -39,9 +39,10 @@
                /// <summary>
                /// Create a new factory instance for a given type
                /// </summary>
-               /// <param name="typeToCreate"></param>
-               /// <returns></returns>
-               public IFactory CreateFactory(Type typeToCreate)
+               /// <param name="typeToCreate">The type instance to 
build</param>
+               /// <param name="types">The types of the constructor 
arguments</param>
+               /// <returns>Returns a new instance factory</returns>
+               public IFactory CreateFactory(Type typeToCreate, Type[] types)
                {
                        return new ActivatorFactory( typeToCreate );
                }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs 
Sun Apr  9 11:24:53 2006
@@ -26,6 +26,7 @@
 using System;
 using System.Collections;
 using System.Collections.Specialized;
+using System.Text;
 
 namespace IBatisNet.Common.Utilities.Objects
 {
@@ -51,26 +52,49 @@
                /// <summary>
                /// Create a new factory instance for a given type
                /// </summary>
-               /// <param name="typeToCreate"></param>
-               /// <returns></returns>
-               public IFactory CreateFactory(Type typeToCreate)
+               /// <param name="typeToCreate">The type instance to 
build</param>
+               /// <param name="types">The types of the constructor 
arguments</param>
+               /// <returns>Returns a new instance factory</returns>
+               public IFactory CreateFactory(Type typeToCreate, Type[] types)
                {
-                       IFactory factory = (IFactory) 
_cachedfactories[typeToCreate];
+                       string key = GenerateKey(typeToCreate, types);
+
+                       IFactory factory = _cachedfactories[key] as IFactory;
                        if (factory == null)
                        {
                                lock (_padlock)
                                {
-                                       factory = (IFactory) 
_cachedfactories[typeToCreate];
+                                       factory = _cachedfactories[key] as 
IFactory;
                                        if (factory == null) // double-check
                                        {
-                                               factory = 
_factoryBuilder.CreateFactory(typeToCreate);
-                                               _cachedfactories[typeToCreate] 
= factory;
+                                               factory = 
_factoryBuilder.CreateFactory(typeToCreate, types);
+                                               _cachedfactories[key] = factory;
                                        }
                                }
                        }
                        return factory;
                }
 
+               /// <summary>
+               /// Generates the key for a cache entry.
+               /// </summary>
+               /// <param name="typeToCreate">The type instance to 
build.</param>
+               /// <param name="arguments">The types of the constructor 
arguments</param>
+               /// <returns>The key for a cache entry.</returns>
+               private string GenerateKey(Type typeToCreate, object[] 
arguments)
+               {
+                       StringBuilder cacheKey = new StringBuilder();
+                       cacheKey.Append(typeToCreate.ToString());
+                       cacheKey.Append(".");
+                       if ((arguments != null) && (arguments.Length != 0)) 
+                       {
+                               for (int i=0; i<arguments.Length; i++) 
+                               {
+                                       
cacheKey.Append(".").Append(arguments[i]);
+                               }
+                       }
+                       return cacheKey.ToString();
+               }
                #endregion
        }
 }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs 
Sun Apr  9 11:24:53 2006
@@ -24,6 +24,7 @@
 #endregion
 
 using System;
+using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
 using IBatisNet.Common.Exceptions;
@@ -52,14 +53,15 @@
 
 
                /// <summary>
-               /// 
+               /// Create a factory which build class of type typeToCreate
                /// </summary>
-               /// <param name="typeToCreate"></param>
-               /// <returns></returns>
-               public IFactory CreateFactory(Type typeToCreate)
+               /// <param name="typeToCreate">The type instance to 
build</param>
+               /// <param name="types">The types of the constructor 
arguments</param>
+               /// <returns>Returns a new instance factory</returns>
+               public IFactory CreateFactory(Type typeToCreate, Type[] types)
                {
-                       Type innerType = CreateFactoryType(typeToCreate);
-                       ConstructorInfo ctor = innerType.GetConstructor(new 
Type[] {});
+                       Type innerType = CreateFactoryType(typeToCreate, types);
+                       ConstructorInfo ctor = 
innerType.GetConstructor(Type.EmptyTypes);
                        return (IFactory) ctor.Invoke(new object[] {});
                }
 
@@ -68,31 +70,108 @@
                /// 
                /// </summary>
                /// <param name="typeToCreate"></param>
+               /// <param name="types"></param>
                /// <returns></returns>
-               private Type CreateFactoryType(Type typeToCreate)
+               private Type CreateFactoryType(Type typeToCreate, Type[] types)
                {
                        TypeBuilder typeBuilder = 
_moduleBuilder.DefineType("EmitFactoryFor" + typeToCreate.Name, 
TypeAttributes.Public);
                        typeBuilder.AddInterfaceImplementation(typeof 
(IFactory));
-                       ImplementCreateInstance(typeBuilder, typeToCreate);
+                       ImplementCreateInstance(typeBuilder, typeToCreate, 
types);
                        return typeBuilder.CreateType();
                }
 
                
                private MethodAttributes createMethodAttributes = 
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot 
| MethodAttributes.Virtual | MethodAttributes.Final;
 
-               private void ImplementCreateInstance(TypeBuilder typeBuilder, 
Type typeToCreate)
+               private void ImplementCreateInstance(TypeBuilder typeBuilder, 
Type typeToCreate, Type[] argumentTypes )
                {
-                       MethodBuilder meth = 
typeBuilder.DefineMethod("CreateInstance", createMethodAttributes, typeof 
(object), Type.EmptyTypes);
+                       // object CreateInstance(object[] parameters);
+                       MethodBuilder meth = 
typeBuilder.DefineMethod("CreateInstance", createMethodAttributes, typeof 
(object), new Type[]{typeof(object[])} );
                        ILGenerator il = meth.GetILGenerator();
 
                        // Add test if contructeur not public
-                       ConstructorInfo ctor = 
typeToCreate.GetConstructor(Type.EmptyTypes);
+                       ConstructorInfo ctor = 
typeToCreate.GetConstructor(argumentTypes);
                        if (!ctor.IsPublic)
                        {
-                               throw new ProbeException(string.Format("Unable 
to optimize create instance for type \"{0}\". Cause no public constructor on 
type. ", typeToCreate.Name));
+                               throw new ProbeException(
+                                       string.Format("Unable to optimize 
create instance. Cause : Could not find public constructor matching specified 
arguments for type \"{0}\".", typeToCreate.Name));
+                       }
+                       if (argumentTypes==Type.EmptyTypes)// no parameters
+                       {
+                               // new typeToCreate()
+                               il.Emit(OpCodes.Newobj, ctor);
+                               il.Emit(OpCodes.Ret);
+                       }
+                       else
+                       {
+                               // new typeToCreate(... arguments ...)
+                               EmitArgsIL(il, argumentTypes);
+                               il.Emit(OpCodes.Newobj, ctor);
+                               il.Emit(OpCodes.Ret);                           
                        }
-                       il.Emit(OpCodes.Newobj, ctor);
-                       il.Emit(OpCodes.Ret);
                }
+
+               /// <summary>   
+               /// Emit parameter IL for a method call.   
+               /// </summary>   
+               /// <param name="il">IL generator.</param>   
+               /// <param name="argumentTypes">Arguments type defined for a 
the constructor.</param>   
+               private void EmitArgsIL(ILGenerator il, Type[] argumentTypes)   
+               {   
+                       // Add args. Since all args are objects, value types 
are unboxed. 
+                       // Refs to value types are to be converted to values 
themselves.   
+                       for (int i = 0; i < argumentTypes.Length; i++)   
+                       {   
+                               // Push args array reference on the stack , 
followed by the index.   
+                               // Ldelem will resolve them to args[i].   
+                               il.Emit(OpCodes.Ldarg_1);   // Argument 1 is 
argument array.
+                               il.Emit(OpCodes.Ldc_I4, i);   
+                               il.Emit(OpCodes.Ldelem_Ref);
+
+                               // If param is a value type then we need to 
unbox it.   
+                               Type paramType = argumentTypes[i];   
+                               if (paramType.IsValueType)   
+                               {   
+                                       il.Emit(OpCodes.Unbox, paramType);  
+                                       
il.Emit(BoxingOpCodes.GetOpCode(paramType)); 
+                               }  
+
+                       }   
+                }   
+
+               /// <summary>  
+               /// Helper class that returns appropriate boxing opcode based 
on type  
+               /// </summary>  
+               /// <remarks>From Spring.NET</remarks>
+               internal class BoxingOpCodes  
+               {  
+                       private static IDictionary boxingOpCodes;  
+ 
+                       static BoxingOpCodes()  
+                       {  
+                               boxingOpCodes = new Hashtable();  
+                               boxingOpCodes[typeof(sbyte)] = 
OpCodes.Ldind_I1;  
+                               boxingOpCodes[typeof(short)] = 
OpCodes.Ldind_I2;  
+                               boxingOpCodes[typeof(int)] = OpCodes.Ldind_I4;  
+                               boxingOpCodes[typeof(long)] = OpCodes.Ldind_I8; 
 
+                               boxingOpCodes[typeof(byte)] = OpCodes.Ldind_U1; 
 
+                               boxingOpCodes[typeof(ushort)] = 
OpCodes.Ldind_U2;  
+                               boxingOpCodes[typeof(uint)] = OpCodes.Ldind_U4; 
 
+                               boxingOpCodes[typeof(ulong)] = 
OpCodes.Ldind_I8;  
+                               boxingOpCodes[typeof(float)] = 
OpCodes.Ldind_R4;  
+                               boxingOpCodes[typeof(double)] = 
OpCodes.Ldind_R8;  
+                               boxingOpCodes[typeof(char)] = OpCodes.Ldind_U2; 
 
+                               boxingOpCodes[typeof(bool)] = OpCodes.Ldind_I1; 
 
+                       }  
+ 
+                       public static OpCode GetOpCode(Type type)  
+                       {  
+                               if (type.IsEnum)  
+                               {  
+                                       type = Enum.GetUnderlyingType(type);  
+                               }  
+                               return (OpCode) boxingOpCodes[type];  
+                       }  
+               } 
        }
 }

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IFactory.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IFactory.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IFactory.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IFactory.cs Sun 
Apr  9 11:24:53 2006
@@ -31,9 +31,24 @@
        /// </summary>
        public interface IFactory
        {
+//             /// <summary>
+//             /// Create a new instance
+//             /// </summary>
+//             /// <returns>A new instance</returns>
+//             object CreateInstance();
+
                /// <summary>
-               /// Create a new instance
+               /// Create a new instance with the specified parameters
                /// </summary>
-               object CreateInstance();
+               /// <param name="parameters">
+               /// An array of values that matches the number, order and type 
+               /// of the parameters for this constructor. 
+               /// </param>
+               /// <remarks>
+               /// If you call a constructor with no parameters, pass null. 
+               /// Anyway, what you pass will be ignore.
+               /// </remarks>
+               /// <returns>A new instance</returns>
+               object CreateInstance(object[] parameters);
        }
 }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IObjectFactory.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IObjectFactory.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IObjectFactory.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/IObjectFactory.cs 
Sun Apr  9 11:24:53 2006
@@ -36,8 +36,9 @@
                /// <summary>
                /// Create a new factory instance for a given type
                /// </summary>
-               /// <param name="typeToCreate"></param>
-               /// <returns></returns>
-               IFactory CreateFactory(Type typeToCreate);
+               /// <param name="typeToCreate">The type instance to 
build</param>
+               /// <param name="types">The types of the constructor 
arguments</param>
+               /// <returns>Returns a new instance factory</returns>
+               IFactory CreateFactory(Type typeToCreate, Type[] types);
        }
 }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/EmitPropertyAccessor.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/EmitPropertyAccessor.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/EmitPropertyAccessor.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/EmitPropertyAccessor.cs
 Sun Apr  9 11:24:53 2006
@@ -187,11 +187,13 @@
                        constructorIL.Emit(OpCodes.Ldarg_0);
                        // Call the base constructor (no args)
                        constructorIL.Emit(OpCodes.Call, 
typeof(object).GetConstructor(Type.EmptyTypes));
+                       // this._name = memberName
                        // Load "this"
                        constructorIL.Emit(OpCodes.Ldarg_0);
                        // Store name in field "_name"
                        constructorIL.Emit(OpCodes.Ldstr, memberName);
                        constructorIL.Emit(OpCodes.Stfld, fieldBuilderName);
+                       // this._memberType = baseMemberType
                        // Store type in field "_memberType"
 //                     constructorIL.Emit(OpCodes.Ldtoken, baseMemberType);
 //                     MethodInfo miGetTypeFromHandle = 
typeof(System.Type).GetMethod("GetTypeFromHandle", new Type[] 
{typeof(System.RuntimeTypeHandle)});

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs 
Sun Apr  9 11:24:53 2006
@@ -66,11 +66,12 @@
                /// <summary>
                /// Create a new factory instance for a given type
                /// </summary>
-               /// <param name="typeToCreate"></param>
-               /// <returns></returns>
-               public IFactory CreateFactory(Type typeToCreate)
+               /// <param name="typeToCreate">The type instance to 
build</param>
+               /// <param name="types">The types of the constructor 
arguments</param>
+               /// <returns>Returns a new instance factory</returns>
+               public IFactory CreateFactory(Type typeToCreate, Type[] types)
                {
-                       return _objectFactory.CreateFactory(typeToCreate);
+                       return _objectFactory.CreateFactory(typeToCreate, 
types);
                }
 
                #endregion

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectProbe.cs 
Sun Apr  9 11:24:53 2006
@@ -457,8 +457,8 @@
                                        {
                                                try 
                                                {
-                                                       IFactory factory = 
objectFactory.CreateFactory(type);
-                                                       child = 
factory.CreateInstance();
+                                                       IFactory factory = 
objectFactory.CreateFactory(type, Type.EmptyTypes);
+                                                       child = 
factory.CreateInstance(Type.EmptyTypes);
 
                                                        SetMemberValue(parent, 
currentPropertyName, child, objectFactory, memberAccessorFactory);
                                                } 

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
 Sun Apr  9 11:24:53 2006
@@ -210,7 +210,7 @@
 
                                if (Type.GetTypeCode(_class) == TypeCode.Object)
                                {
-                                       _objectFactory = 
configScope.SqlMapper.ObjectFactory.CreateFactory(_class);
+                                       _objectFactory = 
configScope.SqlMapper.ObjectFactory.CreateFactory(_class, Type.EmptyTypes);
                                }
 
                                // Load the child node
@@ -290,7 +290,7 @@
 
                        if (typeCode == TypeCode.Object)
                        {
-                               return _objectFactory.CreateInstance();
+                               return _objectFactory.CreateInstance(null);
                        }
                        else
                        {

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs?rev=392799&r1=392798&r2=392799&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs
 Sun Apr  9 11:24:53 2006
@@ -319,7 +319,7 @@
                                if (Type.GetTypeCode(_resultClass) == 
TypeCode.Object &&
                                        (_resultClass.IsValueType == false))
                                {
-                                       _resultClassFactory = 
configurationScope.SqlMapper.ObjectFactory.CreateFactory(_resultClass);   
+                                       _resultClassFactory = 
configurationScope.SqlMapper.ObjectFactory.CreateFactory(_resultClass, 
Type.EmptyTypes);  
                                }
                        }
                        if (_parameterClassName != string.Empty )
@@ -329,7 +329,7 @@
                        if (_listClassName != string.Empty )
                        {
                                _listClass = 
configurationScope.SqlMapper.TypeHandlerFactory.GetType(_listClassName);
-                _listClassFactory = 
configurationScope.SqlMapper.ObjectFactory.CreateFactory(_listClass);
+                _listClassFactory = 
configurationScope.SqlMapper.ObjectFactory.CreateFactory(_listClass, 
Type.EmptyTypes);
                        }
                }
 
@@ -365,7 +365,7 @@
                                }
                                else
                                {
-                                       return 
_resultClassFactory.CreateInstance();
+                                       return 
_resultClassFactory.CreateInstance(null);
                                }
                        }
                }
@@ -377,7 +377,7 @@
                /// <returns>An object which implment IList.</returns>
                public IList CreateInstanceOfListClass()
                {
-            return (IList)_listClassFactory.CreateInstance(); ;
+            return (IList)_listClassFactory.CreateInstance(null); ;
                }
                #endregion
 


Reply via email to