using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace IFramework.Serialization.DataTable
{
///
/// DataTable
///
public static class DataTableTool
{
///
/// 创建数据读取器
///
///
///
///
///
public static IDataReader CreateReader(TextReader streamReader, IDataRow rowReader, IDataExplainer explainer)
{
return new DataReader(streamReader, rowReader, explainer);
}
///
/// 创建数据读取器
///
///
///
///
///
public static IDataReader CreateReader(string text, IDataRow rowReader, IDataExplainer explainer)
{
return new DataReader(text, rowReader, explainer);
}
///
/// 创建数据写入器
///
///
///
///
///
public static IDataWriter CreateWriter(TextWriter streamWriter, IDataRow rowWriter, IDataExplainer explainer)
{
return new DataWriter( streamWriter, rowWriter, explainer);
}
internal static Dictionary GetMemberInfo(Type type)
{
Dictionary members = new Dictionary();
type.GetFields(/*BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static*/)
.ToList().FindAll((field) => { return !field.IsNotSerialized && !field.IsDefined(typeof(DataIgnoreAttribute), false); ; })
.ForEach((field) => {
if (field.IsDefined(typeof(DataColumnNameAttribute), false))
members.Add(field, (field.GetCustomAttributes(typeof(DataColumnNameAttribute),false)[0]
as DataColumnNameAttribute).name);
else
members.Add(field, field.Name);
});
type.GetProperties(/*BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static*/)
.ToList().FindAll((property) => { return !property.IsDefined(typeof(DataIgnoreAttribute), false) && property.CanWrite && property.CanRead; })
.ForEach((property) => {
if (property.IsDefined(typeof(DataColumnNameAttribute), false))
members.Add(property, (property.GetCustomAttributes(typeof(DataColumnNameAttribute), false)[0]
as DataColumnNameAttribute).name);
else
members.Add(property, property.Name);
});
return members;
}
}
}