init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
45
Kreta.BusinessLogic/Utils/JObjectExtensions.cs
Normal file
45
Kreta.BusinessLogic/Utils/JObjectExtensions.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Data;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Kreta.BusinessLogic.Utils
|
||||
{
|
||||
public static class JObjectExtensions
|
||||
{
|
||||
public static DataTable ToDataTable(this JObject jObject)
|
||||
{
|
||||
var props = jObject.Properties();
|
||||
DataTable table = new DataTable();
|
||||
var count = props.Count();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
JProperty prop = props.ElementAt(i);
|
||||
switch (prop.Value.Type)
|
||||
{
|
||||
case JTokenType.Integer:
|
||||
table.Columns.Add(prop.Name, typeof(int));
|
||||
break;
|
||||
default:
|
||||
table.Columns.Add(prop.Name, typeof(string));
|
||||
break;
|
||||
}
|
||||
}
|
||||
object[] values = new object[props.Count()];
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
var prop = props.ElementAt(i);
|
||||
switch (prop.Value.Type)
|
||||
{
|
||||
case JTokenType.Integer:
|
||||
values[i] = prop.Value.Value<int>();
|
||||
break;
|
||||
default:
|
||||
values[i] = prop.Value.Value<string>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
table.Rows.Add(values);
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue