Author: gbayon
Date: Mon Apr 10 10:24:08 2006
New Revision: 392994

URL: http://svn.apache.org/viewcvs?rev=392994&view=rev
Log:
- Fixed Factorybuilder

Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ObjectFactoryTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.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=392994&r1=392993&r2=392994&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs Mon Apr 10 
10:24:08 2006
@@ -16,10 +16,16 @@
                private string _test = string.Empty;
                private Days _days ;
                private Property _prop = null ;
+               private DateTime _date = DateTime.MinValue;
 
                public Account()
                {}
 
+               public Account(DateTime date)
+               {
+                       _date = date;
+               }
+
                public Account(int id)
                {
                        _id = id;
@@ -49,6 +55,11 @@
                public Property Property
                {
                        get { return _prop; }
+               }
+
+               public DateTime Date
+               {
+                       get { return _date; }
                }
 
                public Days Days

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=392994&r1=392993&r2=392994&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
 Mon Apr 10 10:24:08 2006
@@ -102,6 +102,24 @@
                {
                        IObjectFactory objectFactory = new ObjectFactory(true);
 
+                       Type[] types = {typeof(DateTime)};
+                       IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
+
+                       object[] parameters = new object[1];
+                       DateTime date = DateTime.Now;
+                       parameters[0] = date;
+                       object obj = factory.CreateInstance(parameters);
+
+                       Assert.IsTrue(obj is Account);
+                       Account account = (Account)obj;
+                       Assert.AreEqual( date, account.Date);
+               }
+
+               [Test]
+               public void DynamicFactoryWithConstructor6()
+               {
+                       IObjectFactory objectFactory = new ObjectFactory(true);
+
                        Type[] types = {typeof(string), typeof(Property)};
                        IFactory factory = objectFactory.CreateFactory(typeof 
(Account), types );
 

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=392994&r1=392993&r2=392994&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs 
Mon Apr 10 10:24:08 2006
@@ -40,7 +40,7 @@
                private object _padlock = new object();
 
                /// <summary>
-               /// 
+               /// Default constructor
                /// </summary>
                public EmitObjectFactory()
                {

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=392994&r1=392993&r2=392994&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs 
Mon Apr 10 10:24:08 2006
@@ -96,19 +96,10 @@
                                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);                           
-                       }
+                       // new typeToCreate() or new typeToCreate(... arguments 
...)
+                       EmitArgsIL(il, argumentTypes);
+                       il.Emit(OpCodes.Newobj, ctor);
+                       il.Emit(OpCodes.Ret);                           
                }
 
                /// <summary>   
@@ -128,14 +119,21 @@
                                il.Emit(OpCodes.Ldc_I4, i);   
                                il.Emit(OpCodes.Ldelem_Ref);
 
-                               // If param is a value type then we need to 
unbox it.   
+                               // If param is a primitive/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)); 
+                                       if (paramType.IsPrimitive || 
paramType.IsEnum) 
+                                       {
+                                               il.Emit(OpCodes.Unbox, 
paramType);
+                                               
il.Emit(BoxingOpCodes.GetOpCode(paramType));
+                                       }
+                                       else if (paramType.IsValueType) 
+                                       {
+                                               il.Emit(OpCodes.Unbox, 
paramType);
+                                               il.Emit(OpCodes.Ldobj, 
paramType);
+                                       }
                                }  
-
                        }   
                 }   
 


Reply via email to