Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

增加 ToDictionary 方法

  • Loading branch information...
commit 50a54d5b70b76f89c3202f21dd2aae1bbf4bb8dd 1 parent 6f15765
Ivony authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 Sources/Ivony.Data/DataSetExtensions.cs
24 Sources/Ivony.Data/DataSetExtensions.cs
View
@@ -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;
+ }
+
+
+
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.