﻿
{"id":1291,"date":"2013-01-22T23:51:36","date_gmt":"2013-01-22T23:51:36","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=1291"},"modified":"2013-01-22T23:52:36","modified_gmt":"2013-01-22T23:52:36","slug":"c-generic-list-koleksiyonu-datatable-nesnesine-donusturmek","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-generic-list-koleksiyonu-datatable-nesnesine-donusturmek\/","title":{"rendered":"C# Generic List Koleksiyonu DataTable Nesnesine D\u00f6n\u00fc\u015ft\u00fcrmek"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>E\u011fer elinizdeki bir Generic List koleksiyonu DataTable nesnesine d\u00f6n\u00fc\u015ft\u00fcrmek isterseniz a\u015fa\u011f\u0131daki Generic tipinden olan metodu kullanabilirsiniz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        public static DataTable ToDataTable&lt;T&gt;(this IList&lt;T&gt; data)\r\n        {\r\n            PropertyDescriptorCollection properties =\r\n                TypeDescriptor.GetProperties(typeof(T));\r\n            DataTable table = new DataTable();\r\n            foreach (PropertyDescriptor prop in properties)\r\n                table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);\r\n            foreach (T item in data)\r\n            {\r\n                DataRow row = table.NewRow();\r\n                foreach (PropertyDescriptor prop in properties)\r\n                    row&#x5B;prop.Name] = prop.GetValue(item) ?? DBNull.Value;\r\n                table.Rows.Add(row);\r\n            }\r\n            return table;\r\n        }\r\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>E\u011fer elinizdeki bir Generic List koleksiyonu DataTable nesnesine d\u00f6n\u00fc\u015ft\u00fcrmek isterseniz a\u015fa\u011f\u0131daki Generic tipinden olan metodu kullanabilirsiniz. public static DataTable ToDataTable&lt;T&gt;(this IList&lt;T&gt; data) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); DataTable table = new DataTable(); foreach (PropertyDescriptor&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[334,136,333],"class_list":["post-1291","post","type-post","status-publish","format-standard","hentry","category-c-sharp-c","tag-convert","tag-datatable","tag-generic-list"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/1291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=1291"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/1291\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=1291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=1291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=1291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}