using System;
using System.Collections.Generic;
using System.Linq;
namespace FlexFramework.Excel
{
///
/// Extensions
///
public static class Extensions
{
///
/// Convert cell to target type
///
/// Cell
/// /// Target type
/// Target instance
public static object Convert(this Cell cell, Type type)
{
return ValueConverter.Convert(type, cell.Text);
}
///
/// Convert cell to target type
///
/// Target type
/// Cell
/// Target instance
public static T Convert(this Cell cell)
{
return (T)Convert(cell, typeof(T));
}
///
/// Convert row to object instance
///
/// Target type
/// Row
/// Generator
/// Object instance
public static T Convert(this Row row, IGenerator generator) where T : new()
{
return (T)generator.Instantiate(row);
}
///
/// Convert row to object instance
///
/// Target type
/// Row
/// Mapping expression
/// Object instance
public static T Convert(this Row row, string expression) where T : new()
{
return Convert(row, new Mapper().Map(expression));
}
///
/// Convert row to object instance
///
/// Target type
/// Row
/// Mapping provider
/// Object instance
public static T Convert(this Row row, IEnumerable cols) where T : new()
{
return Convert(row, new Mapper().Map(cols));
}
///
/// Convert row to object instance
///
/// Row
/// Target type
/// Mapping expression
/// Object instance
public static object Convert(this Row row, Type type, string expression)
{
return Convert(row, new Mapper(type).Map(expression));
}
///
/// Convert row to object instance
///
/// Row
/// Target type
/// Mapping provider
/// Object instance
public static object Convert(this Row row, Type type, IEnumerable cols)
{
return Convert(row, new Mapper(type).Map(cols));
}
///
/// Convert row to object instance
///
/// Row
/// Generator
/// Object instance
public static object Convert(this Row row, IGenerator generator)
{
return generator.Instantiate(row);
}
///
/// Convert table to target enumerable
///
/// Target type
/// Table
/// Target enumerable
public static IEnumerable Convert(this Table table) where T : new()
{
var mapper = new TableMapper();
mapper.Extract();
return Convert(table, mapper);
}
///
/// Convert table to target enumerable
///
/// Table
/// Target type
/// Target enumerable
public static IEnumerable | |