Permalink
Browse files

增加 ToDictionary 方法

  • Loading branch information...
1 parent 6f15765 commit 50a54d5b70b76f89c3202f21dd2aae1bbf4bb8dd @Ivony committed Dec 14, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 Sources/Ivony.Data/DataSetExtensions.cs
View
24 Sources/Ivony.Data/DataSetExtensions.cs
@@ -48,5 +48,29 @@ public static T[] Column<T>( this DataTable table, string columnName )
}
+ /// <summary>
+ /// 将 DataRow 转换为等效的 Dictionary
+ /// </summary>
+ /// <param name="dataItem">要转换的 DataRow</param>
+ /// <returns>等效的 Dictionary</returns>
+ public static IDictionary<string, object> ToDictionary( this DataRow dataItem )
+ {
+
+ IDictionary<string,object> result;
+
+ var table = dataItem.Table;
+ if ( table.CaseSensitive )
+ result = new Dictionary<string, object>( StringComparer.Ordinal );
+ else
+ result = new Dictionary<string, object>( StringComparer.OrdinalIgnoreCase );
+
+ foreach ( DataColumn column in table.Columns )
+ result.Add( column.ColumnName, dataItem[column] );
+
+ return result;
+ }
+
+
+
}
}

0 comments on commit 50a54d5

Please sign in to comment.