Author: gbayon
Date: Wed Mar 15 14:05:46 2006
New Revision: 386179

URL: http://svn.apache.org/viewcvs?rev=386179&view=rev
Log:
- Added Enum support in ILPropertyAccessor

Added:
    
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorPerformance.cs
   (with props)
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
    ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
    
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs
    
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs

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=386179&r1=386178&r2=386179&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs Wed Mar 15 
14:05:46 2006
@@ -2,6 +2,17 @@
 
 namespace IBatisNet.Common.Test.Domain
 {
+    public enum Days
+    {
+        Sat = 1,
+        Sun,
+        Mon,
+        Tue,
+        Wed,
+        Thu,
+        Fri
+    };
+
        /// <summary>
        /// Summary description for Property.
        /// </summary>
@@ -25,6 +36,7 @@
                private Guid _guid = Guid.Empty;
                private TimeSpan _timeSpan = TimeSpan.MinValue;
                private Account _account = null;
+        private Days _day;
 
 #if dotnet2
         private Int32? _intNullable = null;
@@ -35,6 +47,12 @@
             set { _intNullable = value; }
         }
 #endif
+
+        public Days Day
+        {
+            get { return _day; }
+            set { _day = value; }
+        }
 
                public string String
                {

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj?rev=386179&r1=386178&r2=386179&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj 
Wed Mar 15 14:05:46 2006
@@ -133,6 +133,7 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="NUnit\CommonTests\Utilities\ObjectFactoryTest.cs" />
+    <Compile 
Include="NUnit\CommonTests\Utilities\PropertyAccessorPerformance.cs" />
     <Compile Include="NUnit\CommonTests\Utilities\PropertyAccessorTest.cs" />
     <Compile Include="NUnit\CommonTests\Utilities\ResourcesTest.cs">
       <SubType>Code</SubType>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj?rev=386179&r1=386178&r2=386179&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj 
Wed Mar 15 14:05:46 2006
@@ -300,6 +300,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = 
"NUnit\CommonTests\Utilities\PropertyAccessorPerformance.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = 
"NUnit\CommonTests\Utilities\PropertyAccessorTest.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

Added: 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorPerformance.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorPerformance.cs?rev=386179&view=auto
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorPerformance.cs
 (added)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorPerformance.cs
 Wed Mar 15 14:05:46 2006
@@ -0,0 +1,240 @@
+using System;
+using System.Reflection;
+using IBatisNet.Common.Test.Domain;
+using IBatisNet.Common.Utilities;
+using IBatisNet.Common.Utilities.Objects;
+using NUnit.Framework;
+
+
+namespace IBatisNet.Common.Test.NUnit.CommonTests.Utilities
+{
+    [TestFixture]
+    public class PropertyAccessorPerformance
+    {
+        #region SetUp & TearDown
+
+        /// <summary>
+        /// SetUp
+        /// </summary>
+        [SetUp]
+        public void SetUp()
+        {
+        }
+
+
+        /// <summary>
+        /// TearDown
+        /// </summary>
+        [TearDown]
+        public void Dispose()
+        {
+        }
+
+        #endregion
+
+        /// <summary>
+        /// Test integer property access performance
+        /// </summary>
+        [Test]
+        public void TestGetIntegerPerformance()
+        {
+            const int TEST_ITERATIONS = 1000000;
+            Property prop = new Property();
+            int test = -1;
+            Timer timer = new Timer();
+
+            #region Direct access (fastest)
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                test = -1;
+                test = prop.Int;
+                Assert.AreEqual(int.MinValue, test);
+            }
+            timer.Stop();
+            double directAccessDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            #endregion
+
+            #region IL Property accessor
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            PropertyAccessorFactory factory = new 
PropertyAccessorFactory(true);
+            IPropertyAccessor propertyAccessor = 
factory.CreatePropertyAccessor(typeof(Property), "Int");
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                test = -1;
+                test = (int)propertyAccessor.Get(prop);
+                Assert.AreEqual(int.MinValue, test);
+            }
+            timer.Stop();
+            double propertyAccessorDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            double propertyAccessorRatio = propertyAccessorDuration / 
directAccessDuration;
+            #endregion
+
+            #region IBatisNet.Common.Utilities.Object.ReflectionInfo
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            ReflectionInfo reflectionInfo = 
ReflectionInfo.GetInstance(prop.GetType());
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                test = -1;
+                PropertyInfo propertyInfo = reflectionInfo.GetGetter("Int");
+                test = (int)propertyInfo.GetValue(prop, null);
+                Assert.AreEqual(int.MinValue, test);
+            }
+            timer.Stop();
+            double reflectionInfoDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            double reflectionInfoRatio = (float)reflectionInfoDuration / 
directAccessDuration;
+            #endregion
+
+            #region Reflection
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            Type type = prop.GetType();
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                test = -1;
+                PropertyInfo propertyInfo = type.GetProperty("Int", 
BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
+                test = (int)propertyInfo.GetValue(prop, null);
+                Assert.AreEqual(int.MinValue, test);
+            }
+            timer.Stop();
+            double reflectionDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            double reflectionRatio = reflectionDuration / directAccessDuration;
+            #endregion
+
+            #region ReflectionInvokeMember (slowest)
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                test = -1;
+                test = (int)type.InvokeMember("Int",
+                    BindingFlags.Public | BindingFlags.GetProperty | 
BindingFlags.Instance,
+                    null, prop, null);
+                Assert.AreEqual(int.MinValue, test);
+            }
+            timer.Stop();
+            double reflectionInvokeMemberDuration = 1000000 * (timer.Duration 
/ (double)TEST_ITERATIONS);
+            double reflectionInvokeMemberRatio = 
reflectionInvokeMemberDuration / directAccessDuration;
+            #endregion
+
+            // Print results
+            Console.WriteLine("{0} property gets on integer...", 
TEST_ITERATIONS);
+            Console.WriteLine("Direct access: \t\t{0} ", 
directAccessDuration.ToString("F3"));
+            Console.WriteLine("IPropertyAccessor: \t\t{0} Ratio: {1}", 
propertyAccessorDuration.ToString("F3"), propertyAccessorRatio.ToString("F3"));
+            Console.WriteLine("IBatisNet ReflectionInfo: \t{0} Ratio: {1}", 
reflectionInfoDuration.ToString("F3"), reflectionInfoRatio.ToString("F3"));
+            Console.WriteLine("ReflectionInvokeMember: \t{0} Ratio: {1}", 
reflectionInvokeMemberDuration.ToString("F3"), 
reflectionInvokeMemberRatio.ToString("F3"));
+            Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}", 
reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3"));
+        }
+
+
+        /// <summary>
+        /// Test the performance of getting an integer property.
+        /// </summary>
+        [Test]
+        public void TestSetIntegerPerformance()
+        {
+            const int TEST_ITERATIONS = 1000000;
+            Property prop = new Property();
+            int value = 123;
+            Timer timer = new Timer();
+
+            #region Direct access (fastest)
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                prop.Int = value;
+            }
+            timer.Stop();
+            double directAccessDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            #endregion
+
+            #region Property accessor
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            PropertyAccessorFactory factory = new 
PropertyAccessorFactory(true);
+            IPropertyAccessor propertyAccessor = 
factory.CreatePropertyAccessor(typeof(Property), "Int");
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                propertyAccessor.Set(prop, value);
+            }
+            timer.Stop();
+            double propertyAccessorDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            double propertyAccessorRatio = propertyAccessorDuration / 
directAccessDuration;
+            #endregion
+
+            #region IBatisNet.Common.Utilities.Object.ReflectionInfo
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            Type type = prop.GetType();
+            ReflectionInfo reflectionInfo = ReflectionInfo.GetInstance(type);
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                PropertyInfo propertyInfo = reflectionInfo.GetSetter("Int");
+                propertyInfo.SetValue(prop, value, null);
+            }
+            timer.Stop();
+            double reflectionInfoDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            double reflectionInfoRatio = reflectionInfoDuration / 
directAccessDuration;
+            #endregion
+
+            #region Reflection
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                PropertyInfo propertyInfo = type.GetProperty("Int", 
BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
+                propertyInfo.SetValue(prop, value, null);
+            }
+            timer.Stop();
+            double reflectionDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
+            double reflectionRatio = reflectionDuration / directAccessDuration;
+            #endregion
+
+            #region ReflectionInvokeMember (slowest)
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            timer.Start();
+            for (int i = 0; i < TEST_ITERATIONS; i++)
+            {
+                type.InvokeMember("Int",
+                    BindingFlags.Public | BindingFlags.SetProperty | 
BindingFlags.Instance,
+                    null, prop, new object[] { value });
+            }
+            timer.Stop();
+            double reflectionInvokeMemberDuration = 1000000 * (timer.Duration 
/ (double)TEST_ITERATIONS);
+            double reflectionInvokeMemberRatio = 
reflectionInvokeMemberDuration / directAccessDuration;
+            #endregion
+
+            // Print results
+            Console.WriteLine("{0} property sets on integer...", 
TEST_ITERATIONS);
+            Console.WriteLine("Direct access: \t\t{0} ", 
directAccessDuration.ToString("F3"));
+            Console.WriteLine("IPropertyAccessor: \t\t{0} Ratio: {1}", 
propertyAccessorDuration.ToString("F3"), propertyAccessorRatio.ToString("F3"));
+            Console.WriteLine("IBatisNet ReflectionInfo: \t{0} Ratio: {1}", 
reflectionInfoDuration.ToString("F3"), reflectionInfoRatio.ToString("F3"));
+            Console.WriteLine("ReflectionInvokeMember: \t{0} Ratio: {1}", 
reflectionInvokeMemberDuration.ToString("F3"), 
reflectionInvokeMemberRatio.ToString("F3"));
+            Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}", 
reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3"));
+        }
+    }
+}

Propchange: 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorPerformance.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorPerformance.cs
------------------------------------------------------------------------------
    svn:keywords = Id LastChangedDate LastChangedBy

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs?rev=386179&r1=386178&r2=386179&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
 Wed Mar 15 14:05:46 2006
@@ -61,210 +61,6 @@
                        Assert.AreEqual(int.MinValue, 
propertyAccessor2.Get(prop));
                }
 
-        /// <summary>
-               /// Test integer property access performance
-               /// </summary>
-        [Test]
-        public void TestGetIntegerPerformance()
-        {
-            const int TEST_ITERATIONS = 1000000;
-                       Property prop = new Property();
-                       int test = -1;
-                       Timer timer = new Timer();
-
-                       #region Direct access (fastest)
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-                       timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               test = -1;
-                               test = prop.Int;
-                               Assert.AreEqual(int.MinValue, test);
-                       }
-                       timer.Stop();
-                       double directAccessDuration = 1000000 * (timer.Duration 
/ (double)TEST_ITERATIONS);
-                       #endregion
-
-                       #region IL Property accessor
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-                       PropertyAccessorFactory factory = new 
PropertyAccessorFactory(true);
-                       IPropertyAccessor propertyAccessor = 
factory.CreatePropertyAccessor(typeof(Property), "Int");
-                       timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               test = -1;
-                               test = (int)propertyAccessor.Get(prop);
-                               Assert.AreEqual(int.MinValue, test);
-                       }
-                       timer.Stop();
-                       double propertyAccessorDuration = 1000000 * 
(timer.Duration / (double)TEST_ITERATIONS);
-                       double propertyAccessorRatio = propertyAccessorDuration 
/ directAccessDuration;
-                       #endregion
-
-                       #region IBatisNet.Common.Utilities.Object.ReflectionInfo
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-                       ReflectionInfo reflectionInfo = 
ReflectionInfo.GetInstance(prop.GetType());
-                       timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               test = -1;
-                               PropertyInfo propertyInfo = 
reflectionInfo.GetGetter("Int");
-                               test = (int)propertyInfo.GetValue(prop, null);
-                               Assert.AreEqual(int.MinValue, test);
-                       }
-                       timer.Stop();
-                       double reflectionInfoDuration = 1000000 * 
(timer.Duration / (double)TEST_ITERATIONS);
-                       double reflectionInfoRatio = 
(float)reflectionInfoDuration / directAccessDuration;
-                       #endregion
-
-                       #region Reflection
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-                       Type type = prop.GetType();
-                       timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               test = -1;
-                               PropertyInfo propertyInfo = 
type.GetProperty("Int", BindingFlags.Public | BindingFlags.SetProperty | 
BindingFlags.Instance);
-                               test = (int)propertyInfo.GetValue(prop, null);
-                               Assert.AreEqual(int.MinValue, test);
-                       }
-                       timer.Stop();
-                       double reflectionDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
-                       double reflectionRatio = reflectionDuration / 
directAccessDuration;
-                       #endregion
-
-                       #region ReflectionInvokeMember (slowest)
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-                       timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               test = -1;
-                               test = (int)type.InvokeMember("Int",
-                                       BindingFlags.Public | 
BindingFlags.GetProperty | BindingFlags.Instance,
-                                       null, prop, null);
-                               Assert.AreEqual(int.MinValue, test);
-                       }
-                       timer.Stop();
-                       double reflectionInvokeMemberDuration = 1000000 * 
(timer.Duration / (double)TEST_ITERATIONS);
-                       double reflectionInvokeMemberRatio = 
reflectionInvokeMemberDuration / directAccessDuration;
-                       #endregion
-
-                       // Print results
-                       Console.WriteLine("{0} property gets on integer...", 
TEST_ITERATIONS);
-                       Console.WriteLine("Direct access: \t\t{0} ", 
directAccessDuration.ToString("F3"));
-                       Console.WriteLine("IPropertyAccessor: \t\t{0} Ratio: 
{1}", propertyAccessorDuration.ToString("F3"), 
propertyAccessorRatio.ToString("F3"));
-                       Console.WriteLine("IBatisNet ReflectionInfo: \t{0} 
Ratio: {1}", reflectionInfoDuration.ToString("F3"), 
reflectionInfoRatio.ToString("F3"));
-                       Console.WriteLine("ReflectionInvokeMember: \t{0} Ratio: 
{1}", reflectionInvokeMemberDuration.ToString("F3"), 
reflectionInvokeMemberRatio.ToString("F3"));
-                       Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}", 
reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3"));
-        }
-        
-
-               /// <summary>
-        /// Test the performance of getting an integer property.
-        /// </summary>
-        [Test]
-        public void TestSetIntegerPerformance()
-        {
-            const int TEST_ITERATIONS = 1000000;
-                       Property prop = new Property();
-                       int value = 123;
-            Timer timer = new Timer();
-
-                       #region Direct access (fastest)
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-            timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               prop.Int = value;
-                       }
-            timer.Stop();
-            double directAccessDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
-                       #endregion
-
-                       #region Property accessor
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-                       PropertyAccessorFactory factory = new 
PropertyAccessorFactory(true);
-                       IPropertyAccessor propertyAccessor = 
factory.CreatePropertyAccessor(typeof(Property), "Int");
-                       timer.Start();
-            for (int i = 0; i < TEST_ITERATIONS; i++)
-            {
-                propertyAccessor.Set(prop, value);
-            }
-            timer.Stop();
-            double propertyAccessorDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
-            double propertyAccessorRatio = propertyAccessorDuration / 
directAccessDuration;
-                       #endregion
-
-                       #region IBatisNet.Common.Utilities.Object.ReflectionInfo
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-                       Type type = prop.GetType();
-                       ReflectionInfo reflectionInfo = 
ReflectionInfo.GetInstance(type);
-            timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               PropertyInfo propertyInfo = 
reflectionInfo.GetSetter("Int");
-                               propertyInfo.SetValue(prop, value, null);
-                       }
-            timer.Stop();
-            double reflectionInfoDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
-            double reflectionInfoRatio = reflectionInfoDuration / 
directAccessDuration;
-                       #endregion
-
-                       #region Reflection
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-            timer.Start();
-                       for (int i = 0; i < TEST_ITERATIONS; i++)
-                       {
-                               PropertyInfo propertyInfo = 
type.GetProperty("Int", BindingFlags.Public | BindingFlags.SetProperty | 
BindingFlags.Instance);
-                               propertyInfo.SetValue(prop, value, null);
-                       }
-            timer.Stop();
-            double reflectionDuration = 1000000 * (timer.Duration / 
(double)TEST_ITERATIONS);
-            double reflectionRatio = reflectionDuration / directAccessDuration;
-                       #endregion
-
-                       #region ReflectionInvokeMember (slowest)
-                       GC.Collect();
-                       GC.WaitForPendingFinalizers();
-
-            timer.Start();
-            for (int i = 0; i < TEST_ITERATIONS; i++)
-            {
-                type.InvokeMember("Int",
-                    BindingFlags.Public | BindingFlags.SetProperty | 
BindingFlags.Instance,
-                    null, prop, new object[] { value });
-            }
-            timer.Stop();
-            double reflectionInvokeMemberDuration = 1000000 * (timer.Duration 
/ (double)TEST_ITERATIONS);
-            double reflectionInvokeMemberRatio = 
reflectionInvokeMemberDuration / directAccessDuration;
-                       #endregion
-            
-                       // Print results
-                       Console.WriteLine("{0} property sets on integer...", 
TEST_ITERATIONS);
-            Console.WriteLine("Direct access: \t\t{0} ", 
directAccessDuration.ToString("F3"));
-            Console.WriteLine("IPropertyAccessor: \t\t{0} Ratio: {1}", 
propertyAccessorDuration.ToString("F3"), propertyAccessorRatio.ToString("F3"));
-            Console.WriteLine("IBatisNet ReflectionInfo: \t{0} Ratio: {1}", 
reflectionInfoDuration.ToString("F3"), reflectionInfoRatio.ToString("F3"));
-            Console.WriteLine("ReflectionInvokeMember: \t{0} Ratio: {1}", 
reflectionInvokeMemberDuration.ToString("F3"), 
reflectionInvokeMemberRatio.ToString("F3"));
-            Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}", 
reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3"));
-        }
        
 
                /// <summary>
@@ -1178,6 +974,59 @@
                        Assert.AreEqual(test.FirstName, prop.Account.FirstName);
                
                }
+
+        /// <summary>
+        /// Test the setting null on a Enum property.
+        /// </summary>
+        [Test]
+        public void TestSetNullOnEnumProperty()
+        {
+            Property prop = new Property();
+            prop.Day = Days.Thu;
+
+            PropertyInfo propertyInfo = typeof(Property).GetProperty("Day", 
BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
+            propertyInfo.SetValue(prop, null, null);
+
+            // Property accessor
+            PropertyAccessorFactory factory = new 
PropertyAccessorFactory(true);
+            IPropertyAccessor propertyAccessor = 
factory.CreatePropertyAccessor(typeof(Property), "Day");
+            propertyAccessor.Set(prop, null);
+            //Assert.AreEqual(TimeSpan.MinValue, prop.TimeSpan);
+        }
+
+        /// <summary>
+        /// Test setting an Enum property.
+        /// </summary>
+        [Test]
+        public void TestSetEnum()
+        {
+            Property prop = new Property();
+            prop.Day = Days.Thu;
+
+            // Property accessor
+            PropertyAccessorFactory factory = new 
PropertyAccessorFactory(true);
+            IPropertyAccessor propertyAccessor = 
factory.CreatePropertyAccessor(typeof(Property), "Day");
+            Days test = Days.Wed;
+            propertyAccessor.Set(prop, test);
+            Assert.AreEqual(test, prop.Day);
+        }
+
+        /// <summary>
+        /// Test getting an Enum property.
+        /// </summary>
+        [Test]
+        public void TestGetEnum()
+        {
+            Days test = Days.Wed;
+            Property prop = new Property();
+            prop.Day = test;
+
+            // Property accessor
+            PropertyAccessorFactory factory = new 
PropertyAccessorFactory(true);
+            IPropertyAccessor propertyAccessor = 
factory.CreatePropertyAccessor(typeof(Property), "Day");
+            Assert.AreEqual(test, propertyAccessor.Get(prop));
+        }
+
 
 #if dotnet2
         /// <summary>

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=386179&r1=386178&r2=386179&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryBuilder.cs 
Wed Mar 15 14:05:46 2006
@@ -43,7 +43,7 @@
                public FactoryBuilder()
                {
                        AssemblyName assemblyName = new AssemblyName();
-                       assemblyName.Name = "iBATIS.EmitFactory";
+            assemblyName.Name = "iBATIS.EmitFactory" + 
HashCodeProvider.GetIdentityHashCode(this).ToString();
 
                        // Create a new assembly with one module
                        AssemblyBuilder _assemblyBuilder = 
AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, 
AssemblyBuilderAccess.Run);

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs?rev=386179&r1=386178&r2=386179&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs 
Wed Mar 15 14:05:46 2006
@@ -44,9 +44,9 @@
         private IPropertyAccessor _emittedPropertyAccessor = null;
                private AssemblyBuilder _assemblyBuilder = null;
                private ModuleBuilder _moduleBuilder = null;
+        private object _nullInternal = null;
 
                private static IDictionary _typeToOpcode = new 
HybridDictionary();
-        private static IDictionary _defaultValueType = new HybridDictionary();
 
         /// <summary>
         /// Static constructor
@@ -54,23 +54,6 @@
         /// </summary>
         static ILPropertyAccessor()
         {
-            _defaultValueType[typeof(sbyte)] = (sbyte)0;
-            _defaultValueType[typeof(byte)] = (byte)0;
-            _defaultValueType[typeof(char)] = '\0';
-            _defaultValueType[typeof(short)] = (short)0;
-            _defaultValueType[typeof(ushort)] = (ushort)0;
-            _defaultValueType[typeof(int)] = 0;
-            _defaultValueType[typeof(uint)] = (uint)0;
-            _defaultValueType[typeof(long)] = 0L;
-            _defaultValueType[typeof(ulong)] = (ulong)0;
-            _defaultValueType[typeof(bool)] = false;
-            _defaultValueType[typeof(double)] = 0.0D;
-            _defaultValueType[typeof(float)] = 0.0F;
-                       _defaultValueType[typeof(decimal)] = 0.0M;
-                       _defaultValueType[typeof(DateTime)] = DateTime.MinValue;
-                       _defaultValueType[typeof(Guid)] = Guid.Empty;
-                       _defaultValueType[typeof(TimeSpan)] = TimeSpan.MinValue;
-
             _typeToOpcode[typeof(sbyte)] = OpCodes.Ldind_I1;
             _typeToOpcode[typeof(byte)] = OpCodes.Ldind_U1;
             _typeToOpcode[typeof(char)] = OpCodes.Ldind_U2;
@@ -134,17 +117,49 @@
                /// <param name="value">Value to set.</param>
                public void Set(object target, object value)
                {
-            // If the value to assign is null and this property
-            // accessor is for a value type, use a default value instead
+            // If the value to assign is null and assign null internal value
             object newValue = value;
-            if (newValue == null && _propertyType.IsValueType)
+            if (newValue == null)
             {
-                newValue = _defaultValueType[_propertyType];
+                newValue = _nullInternal;
             }
 
             this._emittedPropertyAccessor.Set(target, newValue);
                }
 
+        private object GetNullInternal(Type type)
+        {
+            if (type.IsValueType)
+            {
+                if (type.IsEnum) { return 0; }
+
+                if (type.IsPrimitive)
+                {
+                    if (type == typeof(Int32)) {return 0; }
+                    if (type == typeof(Double)) {return (Double)0; }
+                    if (type == typeof(Int16)) {return (Int16)0; }
+                    if (type == typeof(SByte)) {return (SByte)0; }
+                    if (type == typeof(Int64)) {return (Int64)0; }
+                    if (type == typeof(Byte)) {return (Byte)0; }
+                    if (type == typeof(UInt16)) {return (UInt16)0; }
+                    if (type == typeof(UInt32)) {return (UInt32)0; }
+                    if (type == typeof(UInt64)) {return (UInt64)0; }
+                    if (type == typeof(UInt64)) {return (UInt64)0; }
+                    if (type == typeof(Single)) {return (Single)0; }
+                    if (type == typeof(Boolean)) {return false; }
+                    if (type == typeof(char)) {return '\0'; }
+                }
+                else
+                {
+                    if (type == typeof(DateTime)) {return DateTime.MinValue; }
+                    if (type == typeof(Decimal)) {return 0m; }
+                    if (type == typeof(Guid)) {return Guid.Empty; }
+                    if (type == typeof(TimeSpan)) { return TimeSpan.MinValue; }
+                }
+            }
+ 
+            return null;
+        }
 
                /// <summary>
                /// This method generates creates a new assembly containing
@@ -156,6 +171,8 @@
             EmitType();
 
             _emittedPropertyAccessor = 
_assemblyBuilder.CreateInstance("PropertyAccessorFor" + _targetType.FullName + 
_propertyName) as IPropertyAccessor;
+            
+            _nullInternal = GetNullInternal(_propertyType);
 
                        if(_emittedPropertyAccessor == null)
                        {


Reply via email to