List GroupBy真实用法,Reflection(反射)用法,Enum用法,正则,搜索下拉布局
1.List GroupBy 用法
var _roomProducts = homesingProducts.GroupBy(t => t.RoomName);
RoomedProducts temp = new RoomedProducts();
foreach (var item in _roomProducts)
{
roomNames.Add(item.Key); temp = new RoomedProducts();
temp.RoomName = item.Key;
temp.Products = new List<TempProductInfo>();
temp.Products.AddRange(item); roomedProducts.Add(temp);
}
2.枚举类配合反射使用(避免到处出现 order.state == 50 order.statedesc =="已付款" 等等带有常量的代码)
public enum DesignOrderState
{ /// <summary>
/// 待付款
/// </summary>
[Description("待付款")]
WaitPaying = , /// <summary>
/// 已付款
/// </summary>
[Description("已付款")]
Paid = , /// <summary>
/// 设计中
/// </summary>
[Description("设计中")]
Designing = , /// <summary>
/// 已交付
/// </summary>
[Description("已交付")]
Completed = , } /// <summary>
/// 根据类名获取所有public属性名和特性Description
/// </summary>
/// <param name="className">类名</param>
/// <returns>Dictionary<属性名,Description></returns>
public static Dictionary<string, string> ReflectFiledsNameByClassName(string className)
{
Dictionary<string, string> result = new Dictionary<string, string>();
Type t = Type.GetType(className);
PropertyInfo[] properties = t.GetProperties();
string attr = "";
foreach (var item in properties)
{
foreach (Attribute _attr in Attribute.GetCustomAttributes(item))
{
if (_attr.GetType() == typeof(DescriptionAttribute))
{
attr = ((DescriptionAttribute)_attr).Description;
}
}
result.Add(item.Name, attr);
attr = "";
}
return result;
} /// <summary>
/// 获取枚举类的字段名及值
/// </summary>
/// <param name="type"> typeof(枚举类) </param>
/// <returns></returns>
public static Dictionary<string, int> ReflectEnumFiledAndValues(Type type)
{
Dictionary<string, int> result = new Dictionary<string, int>(); FieldInfo[] properties = type.GetFields();
foreach (var item in properties)
{
try
{
result.Add(item.Name, (int)(Enum.Parse(type, item.Name)));// 得到的第一个属性是 value_ 暂时还不知道为什么
}
catch (Exception)
{ }
}
return result; } /// <summary>
/// 根据枚举类的字段名获取特性Description中的中文描述信息
/// </summary>
/// <param name="className">枚举类名 示:SoftOrderState</param>
/// <param name="filedName">枚举类字段名 示:(SoftOrderState)30 </param>
/// <returns></returns>
public static string ReflectFiledsNameByEnumClassName(string className, string filedName)
{
string result = "";
Type t = Type.GetType(className);
FieldInfo[] properties = t.GetFields();
int length = properties.Length;
for (int i = ; i < length; i++)
{
if (properties[i].Name == filedName)
{
DescriptionAttribute attr = Attribute.GetCustomAttribute(properties[i],
typeof(DescriptionAttribute), false) as DescriptionAttribute;
result = attr.Description;
break;
}
} return result;
} Dictionary<string, string> fileds = new Dictionary<string, string>();
Dictionary<string, int> filedValues = new Dictionary<string, int>(); ReflectFiledsNameByEnumClassName(className, SoftOrderState.Sending.ToString())); //属性 找 Description ReflectFiledsNameByEnumClassName(className,((SoftOrderState)).ToString())); // 值 找 Description (int)((Enum.Parse(typeof(SoftOrderState), "Sending")))); // 属性 to 值 fileds = ReflectFiledsNameByClassName(className); //类名 找 属性名及对应的Description filedValues = ReflectEnumFiledAndValues(typeof(SoftOrderState));// 返回 所有字段和值的键值对
public enum EnumWorkTypes
{
家居住宅,
酒店,
别墅住宅,
办公室,
酒吧KTV
} var types = "";
var typs = typeof(EnumWorkTypes).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
foreach (var fi in typs)
types += "<li value=" + fi.Name + ">" + fi.Name + "</li>"; Response.Write(types);
3.正则备忘
var password = $("#password").val();
if (!(/^[\w\d.,\?]{5,15}$/).test(password)) {
alert("密码不能输入特殊字符并且长度为5到15");
return;
}
// 正则用 ^ 跟 $ 包起来表示匹配本身 (要限制长度必须包起来) ,如果不包就表示字符串中匹配到5-15长度的一段字符,条件就为真
// 手机号码
var mobile = $("#mobile").val();
if (!(/^1[34578]\d{9}$/.test(mobile))) {
alert('手机号码格式错误!');
return ;
}
// 生成随机字符串
function generateAccountAndPwd() {
var x = 1000000;
var y = 1;
// var rand1 = String.fromCharCode(Math.floor(Math.random() * 26) + "A".charCodeAt(0)) + String.fromCharCode(Math.floor(Math.random() * 26) + "A".charCodeAt(0)) + parseInt(Math.random() * (x - y + 1) + y) + String.fromCharCode(Math.floor(Math.random() * 26) + "A".charCodeAt(0)) + parseInt(Math.random() * (x - y + 1) + y) + String.fromCharCode(Math.floor(Math.random() * 26) + "A".charCodeAt(0));
var rand2 = String.fromCharCode(Math.floor(Math.random() * 26) + "a".charCodeAt(0)) + parseInt(Math.random() * (x - y + 1) + y) + String.fromCharCode(Math.floor(Math.random() * 26) + "a".charCodeAt(0));
$("#password").val(rand2);
};
4.搜索配下拉布局

List GroupBy真实用法,Reflection(反射)用法,Enum用法,正则,搜索下拉布局的更多相关文章
- MVC图片上传详解 IIS (安装SSL证书后) 实现 HTTP 自动跳转到 HTTPS C#中Enum用法小结 表达式目录树 “村长”教你测试用例 引用provinces.js的三级联动
MVC图片上传详解 MVC图片上传--控制器方法 新建一个控制器命名为File,定义一个Img方法 [HttpPost]public ActionResult Img(HttpPostedFile ...
- 简学Python第七章__class面向对象高级用法与反射
Python第七章__class面向对象高级用法与反射 欢迎加入Linux_Python学习群 群号:478616847 目录: Python中关于oop的常用术语 类的特殊方法 元类 反射 一.P ...
- Java Enum用法详解
Java Enum用法详解 用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举 ...
- Java反射的常见用法
反射的常见用法有三类,第一类是“查看”,比如输入某个类的属性方法等信息,第二类是“装载“,比如装载指定的类到内存里,第三类是“调用”,比如通过传入参数,调用指定的方法. 1 查看属性的修饰符.类型和名 ...
- Java Reflection 反射基础
反射基础: package reflection; /** * Created by : Infaraway * DATE : 2017/3/2 * Time : 23:06 * Funtion : ...
- 代替Reflection(反射)的一些方法
Reflection(反射)是深入学习.Net必须掌握的技能之一.最初学Reflection的时候,的确是被惊住了,原来还可以这样.只要给你一个Assembly, 你就能获取到其中所有的类型,根据类型 ...
- 代替Reflection(反射)的一些方法(转)
作者:JustRun 林肯: http://www.cnblogs.com/JustRun1983/p/3830764.html 代替Reflection(反射)的一些方法(转) 2014-07-08 ...
- Android-PullToRefresh下拉刷新库基本用法
How:(使用) 转自:http://blog.csdn.net/hantangsongming/article/details/42490277 PullToRefresh是一套实现非常好的下拉刷新 ...
- 子查询。ANY三种用法。ALL两种用法。HAVING中使用子查询。SELECT中使用子查询。
子查询存在的意义是解决多表查询带来的性能问题. 子查询返回单行多列: ANY三种用法: ALL两种用法: HAVING中的子查询返回单行单列: SELECT中使用子查询:(了解就好,避免使用这种方法! ...
随机推荐
- Django订单接入支付宝
1.. 去支付宝申请 https://open.alipay.com/platform/home.htm 注:因为创建应用正式接入支付宝需要营业执照,所以我们可以使用沙箱环境来测试. 2. 一次选择管 ...
- Entity Framework入门教程(18)---EF6中基于代码进行配置方式
EF6中基于代码进行配置方式 我们以前对EF进行配置时是在app.config/web.config下的<entityframework>节点下进行配置的,EF6引进了基于代码的配置方法. ...
- Coursera, Big Data 2, Modeling and Management Systems (week 4/5/6)
week4 streaming data format 下面讲 data lakes schema-on-read: 从数据源读取raw data 直接放到 data lake 里,然后再读到mode ...
- Ubuntu解决没有可安装候选软件包
解决方法:可以使用apt-cache search <package_name>寻找. 例如: E: 软件包 libqglviewer-dev 没有可安装候选 解决方法: apt-cach ...
- AC自动机算法详解 (转载)
首先简要介绍一下AC自动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之一.一个常见的例子就是给出n个单词,再给出一段包含m个字符的文章, ...
- 「CTSC2018」暴力写挂
毫无$ Debug$能力 全世界就我会被卡空间.jpg LOJ #2553 UOJ #400 Luogu P4565 题意 给定两棵树$ T,T'$,求一组点对$ (x,y)$使得$deep(x)+d ...
- (二)Java工程化--Maven实践
Maven项目版本号 默认版本号: 1.0-SNAPSHOT 最佳实践是约定该版本为不稳定版本,如果发布一定要删除; 建议的版本规则: 主版本号.次版本号.增量版本号- 如:1.0.0-RELEASE ...
- python中的赋值操作
参考:https://www.cnblogs.com/andywenzhi/p/7453374.html?tdsourcetag=s_pcqq_aiomsg(写的蛮好) python中的赋值操作“=” ...
- C++设计模式——外观模式
前言 在实际开发时,面对一个大的系统,总是会将一个大的系统分成若干个子系统,等子系统完成之后,再分别调用对应的子系统来完成对应的整体功能,这样有利于降低系统的复杂性:最终进行实现某个具体的功能时,我们 ...
- memcached性能测试之Twemperf
Twemperf又名mcperf,是一款memcached的性能测试工具.Mcperf就像httperf,但它基于memcached的协议,它使用memcached的ASCII协议并且能够快速的产生大 ...