Author: rgrabowski
Date: Sun Jul 16 11:09:24 2006
New Revision: 422486

URL: http://svn.apache.org/viewvc?rev=422486&view=rev
Log:
Added "datatable" alias to TypeRegistry. Started to add special cases (similiar 
to IDictionary special cases) for accessing DataRow items.

Modified:
    
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ObjectProbe.cs
    
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ReflectionInfo.cs
    
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/TypesResolver/TypeRegistry.cs

Modified: 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ObjectProbe.cs
URL: 
http://svn.apache.org/viewvc/ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ObjectProbe.cs?rev=422486&r1=422485&r2=422486&view=diff
==============================================================================
--- 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ObjectProbe.cs
 (original)
+++ 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ObjectProbe.cs
 Sun Jul 16 11:09:24 2006
@@ -26,6 +26,7 @@
 
 using System;
 using System.Collections;
+using System.Data;
 using System.Reflection;
 
 using IBatisNet.Common.Exceptions;
@@ -117,7 +118,20 @@
                                {
                                        type = value.GetType();
                                }
-                       } 
+                       }
+                       else if (obj is DataRow)
+                       {
+                               DataRow dataRow = (DataRow) obj;
+                               object value = dataRow[memberName];
+                               if (value == null) 
+                               {
+                                       type = typeof(object);
+                               } 
+                               else 
+                               {
+                                       type = value.GetType();
+                               }
+                       }
                        else 
                        {
                                if (memberName.IndexOf('.') > -1) 
@@ -194,6 +208,19 @@
                                        type = value.GetType();
                                }
                        } 
+                       else if (obj is DataRow)
+                       {
+                               DataRow dataRow = (DataRow) obj;
+                               object value = dataRow[memberName];
+                               if (value == null) 
+                               {
+                                       type = typeof(object);
+                               } 
+                               else 
+                               {
+                                       type = value.GetType();
+                               }
+                       }
                        else 
                        {
                                if (memberName.IndexOf('.') > -1) 
@@ -436,19 +463,23 @@
                                        {
                                                value = ((IDictionary) 
obj)[memberName];
                                        } 
+                                       else if (obj is DataRow)
+                                       {
+                                               value = ((DataRow) 
obj)[memberName];
+                                       }
                                        else 
                                        {
                                                Type targetType = obj.GetType();
-                        IGetAccessorFactory getAccessorFactory = 
accessorFactory.GetAccessorFactory;
-                        IGetAccessor getAccessor = 
getAccessorFactory.CreateGetAccessor(targetType, memberName);
+                                               IGetAccessorFactory 
getAccessorFactory = accessorFactory.GetAccessorFactory;
+                                               IGetAccessor getAccessor = 
getAccessorFactory.CreateGetAccessor(targetType, memberName);
 
-                        if (getAccessor == null) 
+                                               if (getAccessor == null) 
                                                {
                                                        throw new 
ProbeException("No Get method for member " + memberName + " on instance of " + 
obj.GetType().Name);
                                                }
                                                try 
                                                {
-                            value = getAccessor.Get(obj);
+                                                       value = 
getAccessor.Get(obj);
                                                } 
                                                catch (Exception ae) 
                                                {
@@ -541,19 +572,23 @@
                                        {
                                                ((IDictionary) obj)[memberName] 
= memberValue;
                                        } 
+                                       else if (obj is DataRow)
+                                       {
+                                               ((DataRow) obj)[memberName] = 
memberValue;
+                                       }
                                        else 
                                        {
                                                Type targetType = obj.GetType();
-                        ISetAccessorFactory setAccessorFactory = 
accessorFactory.SetAccessorFactory;
-                        ISetAccessor setAccessor = 
setAccessorFactory.CreateSetAccessor(targetType, memberName);
+                                               ISetAccessorFactory 
setAccessorFactory = accessorFactory.SetAccessorFactory;
+                                               ISetAccessor setAccessor = 
setAccessorFactory.CreateSetAccessor(targetType, memberName);
 
-                        if (setAccessor == null) 
+                                               if (setAccessor == null) 
                                                {
                                                        throw new 
ProbeException("No Set method for member " + memberName + " on instance of " + 
obj.GetType().Name);
                                                }
                                                try 
                                                {
-                            setAccessorFactory.CreateSetAccessor(targetType, 
memberName).Set(obj, memberValue);
+                                                       
setAccessorFactory.CreateSetAccessor(targetType, memberName).Set(obj, 
memberValue);
                                                }
                                                catch (Exception ex) 
                                                {
@@ -585,7 +620,11 @@
                        if (obj is IDictionary) 
                        {
                                hasProperty = ((IDictionary) 
obj).Contains(propertyName);
-                       } 
+                       }
+                       else if (obj is DataRow)
+                       {
+                               hasProperty = ((DataRow) 
obj).Table.Columns.Contains(propertyName);
+                       }
                        else 
                        {
                                if (propertyName.IndexOf('.') > -1) 
@@ -626,6 +665,10 @@
                        {
                                hasProperty = ((IDictionary) 
obj).Contains(propertyName);
                        } 
+                       else if (obj is DataRow)
+                       {
+                               hasProperty = ((DataRow) 
obj).Table.Columns.Contains(propertyName);
+                       }
                        else 
                        {
                                if (propertyName.IndexOf('.') > -1) 
@@ -669,6 +712,10 @@
                        {
                                return true;
                        } 
+                       else if (typeof(DataRow).IsAssignableFrom(type))
+                       {
+                               return true;
+                       }
                        else if (typeof(IList).IsAssignableFrom(type)) 
                        {
                                return true;

Modified: 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ReflectionInfo.cs
URL: 
http://svn.apache.org/viewvc/ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ReflectionInfo.cs?rev=422486&r1=422485&r2=422486&view=diff
==============================================================================
--- 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ReflectionInfo.cs
 (original)
+++ 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/Objects/ReflectionInfo.cs
 Sun Jul 16 11:09:24 2006
@@ -27,6 +27,7 @@
 using System;
 using System.Collections;
 using System.Collections.Specialized;
+using System.Data;
 using System.Reflection;
 
 using IBatisNet.Common.Exceptions;
@@ -296,6 +297,10 @@
                        {
                                return true;
                        } 
+                       else if (typeof(DataRow).IsAssignableFrom(type))
+                       {
+                               return true;
+                       }
                        else if (typeof(IEnumerator).IsAssignableFrom(type)) 
                        {
                                return true;

Modified: 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/TypesResolver/TypeRegistry.cs
URL: 
http://svn.apache.org/viewvc/ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/TypesResolver/TypeRegistry.cs?rev=422486&r1=422485&r2=422486&view=diff
==============================================================================
--- 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/TypesResolver/TypeRegistry.cs
 (original)
+++ 
ibatis/branches/IBatisNet.Common-QueryForDataTable/Utilities/TypesResolver/TypeRegistry.cs
 Sun Jul 16 11:09:24 2006
@@ -29,6 +29,7 @@
 using System;
 using System.Collections;
 using System.Collections.Specialized;
+using System.Data;
 
 #endregion
 
@@ -53,6 +54,8 @@
        {
                #region Constants
 
+               public const string DataTableAlias = "datatable";
+
                /// <summary>
                /// The alias around the 'list' type.
                /// </summary>
@@ -337,6 +340,8 @@
         static TypeRegistry()
                {
                        // Initialize a dictionary with some fully qualifiaed 
name 
+                       _types[DataTableAlias] = typeof (DataTable);
+
                        _types[ArrayListAlias1] = typeof (ArrayList);
                        _types[ArrayListAlias2] = typeof (ArrayList);
 


Reply via email to