ImportCommon
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks; namespace WLYD.Utility.File
{
public class ImportCommon
{ public static string TitleRequiredValidate(PropertyInfo[] properties, Dictionary<int, string> titleDic)
{
foreach (var property in properties)
{
var attr = (DisplayAttribute)property.GetCustomAttribute(typeof(DisplayAttribute), false);
if (attr != null && !string.IsNullOrEmpty(attr.Name))
{
if (!titleDic.Values.Any(h => h == attr.Name))
{
return attr.Name;
}
}
}
return null;
} public static object StringToPropertyValue(PropertyInfo property, string src)
{
object obj = null;
switch (property.PropertyType.Name)
{
case "String":
return src;
case "Decimal":
return decimal.Parse(src);
case "Int32":
return int.Parse(src);
case "DateTime":
return DateTime.Parse(src);
case "Boolean":
return bool.Parse(src);
}
return obj;
} public static string GetPropertyByExcelName(PropertyInfo[] properties, string excelTitleName)
{
foreach (var property in properties)
{
var attr = (DisplayAttribute)property.GetCustomAttribute(typeof(DisplayAttribute), false);
if (attr != null && attr.Name == excelTitleName)
{
return property.Name;
}
}
return null;
} /// <summary>
/// 获取流编码
/// </summary>
/// <param name="fs"></param>
/// <returns></returns>
public static Encoding GetStreamEncode(Stream fs)
{
System.IO.BinaryReader br = new System.IO.BinaryReader(fs); Byte[] buffer = br.ReadBytes(2); if (buffer[0] >= 0xEF) { if (buffer[0] == 0xEF && buffer[1] == 0xBB) { return System.Text.Encoding.UTF8; } else if (buffer[0] == 0xFE && buffer[1] == 0xFF) { return System.Text.Encoding.BigEndianUnicode; } else if (buffer[0] == 0xFF && buffer[1] == 0xFE) { return System.Text.Encoding.Unicode; } else { return System.Text.Encoding.Default; } } else { return System.Text.Encoding.Default; }
}
}
}
ImportCommon的更多相关文章
随机推荐
- gulp-gulpfile.js语法说明
关于gulpfile文件: 直接上代码吧!! /*! * gulp * $ npm install gulp gulp-ruby-sass gulp-cached gulp-uglify gulp-r ...
- CrtmpServer 接收推送视频流 注册流基本流程
今天研究了CrtmpServer 将客户端推动过来的视频流注册到服务的流程,记录下来,以备后用. 图1 注册前端视频流流程
- PHP工作模型与运行机制
PHP的工作模型非常特殊.从某种程度上说,PHP和ASP.ASP.NET.JSP/Servlet等流行的Web技术,有着本质上的区别. 以Java为例,Java在Web应用领域,有两种技术:Jav ...
- pandas-数据分析
pandas是一个强大的python数据分析的工具包 pandas是基于numpy构建的 pandas的主要功能: 具备对其功能的数据结构DataFrame.Series 集成世间序列功能 提供丰富的 ...
- Mataplotlib绘图和可视化
Mataplotlib是一个强大的python绘图和数据可视化工具包 安装方法:pip install matplotlib 引用方法:import matplotlib.pyplot as plt ...
- Django框架学习——python模拟Django框架(转载)
原贴来源 http://wiki.woodpecker.org.cn/moin/ObpLovelyPython/AbtWebModules python实现web服务器 web开发首先要有web服务器 ...
- .Net 中的反射(动态创建类型实例)
动态创建对象 在前面节中,我们先了解了反射,然后利用反射查看了类型信息,并学习了如何创建自定义特性,并利用反射来遍历它.可以说,前面三节,我们学习的都是反射是什么,在接下来的章节中,我们将学习反射可以 ...
- SAM4E单片机之旅——3、LED闪烁之定时器中断
让一个LED灯闪烁不过瘾,我们应该让这块开发板完成一点更高难度的任务:比如让两个LED灯闪烁. …… 当然了,以我们的现在使用的空循环技术,还是可以实现这点的.但是这样显得略为低端.所以我们使用一个高 ...
- EasyDarwin手机直播是如何实现的快速显示视频的方法
前言 经常有人提到最近比较火的映客直播.花椒直播这种,是如何做到在打开手机直播中的某一个主播房间后,立即就能显示出主播视频,非常非常快,而且延时也比较小,是怎么做到的? 其实,这并不是什么高深的技术, ...
- git基本操作---持续更新(2017-08-11)
git 强制push $ git push -u origin master -f 查看本地标签 $ git tag 打标签并添加备注 $ git tag 20170811 -m"图片保存多 ...