1 public class EnumInfo : IPrimaryKey<string> 2 { 3 // Methods 4 public string GetKey() 5 { 6 return this.Name; 7 } 8 9 // Properties 10 public string DefaultValue { get; set; } 11 12 public string Description { get; set; } 13 14 public string Name { get; set; } 15 16 public object Value { get; set; } 17 } 18 19 public class EnumInfoCollection : Collection<EnumInfo> 20 { 21 // Methods 22 public EnumInfoCollection() 23 { 24 } 25 26 public EnumInfoCollection(EnumInfoCollection items) 27 { 28 if (items != null) 29 { 30 foreach (EnumInfo info in items) 31 { 32 base.Add(info); 33 } 34 } 35 } 36 } |
1 public enum CategoriesType : int 2 { 3 [Description("文章栏目")] 4 [DefaultValue(0)] 5 Article, 6 7 [Description("产品栏目")] 8 [DefaultValue(1)] 9 Product, 10 11 [Description("下载栏目")] 12 [DefaultValue(0)] 13 Dowload, 14 15 [Description("图片栏目")] 16 [DefaultValue(0)] 17 Images, 18 19 } |
1 public class EnumUtil 2 { 3 public static EnumInfoCollection GetEnumItems(Type enumType) 4 { 5 EnumInfoCollection infos = new EnumInfoCollection(); 6 FieldInfo[] fields = enumType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); 7 foreach (FieldInfo info2 in fields) 8 { 9 EnumInfo item = new EnumInfo 10 { 11 Name = info2.Name 12 }; 13 DescriptionAttribute[] customAttributes = (DescriptionAttribute[])info2.GetCustomAttributes(typeof(DescriptionAttribute), true); 14 if ((customAttributes != null) && (customAttributes.Length > 0)) 15 { 16 item.Description = customAttributes[0].Description; 17 } 18 DefaultValueAttribute[] attributeArray2 = (DefaultValueAttribute[])info2.GetCustomAttributes(typeof(DefaultValueAttribute), true); 19 if ((attributeArray2 != null) && (attributeArray2.Length > 0)) 20 { 21 item.DefaultValue = attributeArray2[0].Value as string; 22 } 23 object obj2 = enumType.InvokeMember(info2.Name, BindingFlags.GetField, null, null, null); 24 switch (Enum.GetUnderlyingType(enumType).FullName) 25 { 26 case "System.Int32": 27 item.Value = (int)obj2; 28 break; 29 30 case "System.Int16": 31 item.Value = (short)obj2; 32 break; 33 34 case "System.Byte": 35 item.Value = (byte)obj2; 36 break; 37 38 case "System.UInt16": 39 item.Value = Convert.ToInt32((ushort)obj2); 40 break; 41 42 case "System.UInt32": 43 item.Value = (int)obj2; 44 break; 45 46 case "System.UInt64": 47 item.Value = (int)obj2; 48 break; 49 } 50 infos.Add(item); 51 } 52 return infos; 53 } 54 55 public static bool TryParse<T>(string memberName, out T t) where T : struct 56 { 57 t = default(T); 58 return (!memberName.IsNullOrEmpty() && Enum.TryParse<T>(memberName, true, out t)); 59 } 60 61 } |
1 public class EnumUtil 2 { 3 public static EnumInfoCollection GetEnumItems(Type enumType) 4 { 5 EnumInfoCollection infos = new EnumInfoCollection(); 6 FieldInfo[] fields = enumType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); 7 foreach (FieldInfo info2 in fields) 8 { 9 EnumInfo item = new EnumInfo 10 { 11 Name = info2.Name 12 }; 13 DescriptionAttribute[] customAttributes = (DescriptionAttribute[])info2.GetCustomAttributes(typeof(DescriptionAttribute), true); 14 if ((customAttributes != null) && (customAttributes.Length > 0)) 15 { 16 item.Description = customAttributes[0].Description; 17 } 18 DefaultValueAttribute[] attributeArray2 = (DefaultValueAttribute[])info2.GetCustomAttributes(typeof(DefaultValueAttribute), true); 19 if ((attributeArray2 != null) && (attributeArray2.Length > 0)) 20 { 21 item.DefaultValue = attributeArray2[0].Value as string; 22 } 23 object obj2 = enumType.InvokeMember(info2.Name, BindingFlags.GetField, null, null, null); 24 switch (Enum.GetUnderlyingType(enumType).FullName) 25 { 26 case "System.Int32": 27 item.Value = (int)obj2; 28 break; 29 30 case "System.Int16": 31 item.Value = (short)obj2; 32 break; 33 34 case "System.Byte": 35 item.Value = (byte)obj2; 36 break; 37 38 case "System.UInt16": 39 item.Value = Convert.ToInt32((ushort)obj2); 40 break; 41 42 case "System.UInt32": 43 item.Value = (int)obj2; 44 break; 45 46 case "System.UInt64": 47 item.Value = (int)obj2; 48 break; 49 } 50 infos.Add(item); 51 } 52 return infos; 53 } 54 55 public static bool TryParse<T>(string memberName, out T t) where T : struct 56 { 57 t = default(T); 58 return (!memberName.IsNullOrEmpty() && Enum.TryParse<T>(memberName, true, out t)); 59 } 60 61 } |
5.数据操作类,能怎么处理让DataAccess层更规范。
6.Plugin怎么管理。
7.Widgets怎么管理。
8.你是否还在死守Dao,Business,Web,Entity(Model)这样的分层结构,这种从Foosun.Net(cms),PetShop流传出来的结构,是否毒害了你对程序的结构的创想。
9.Template Engin,你是否尝试去处理实现过,请抛弃NVelocity带给你的毒害。是能否从Discuzz!NT中获得点灵感。或者Asp.net mvc模版运行原理你是否清晰,实现原理是否能找到核心代码实现处。
10. 伪静态,原理,实现。是否尝试过用。
11. 静态HTML生成系统你是否尝试用,自己是否尝试过写。
12. 接口类,抽象类,实现类,管理类,代理类,创建型类,行为型类,装饰型类,实体型类,枚举类等,你是否在程序创建类时对他们命名,文件存放位置,结构划分有过深思熟虑。
备注1:
什么代码算上好:
1,代码书写规范;
2,代码结构合理;
3,代码变量,函数,类,命名空间,项目名称规范;
4,代码注释完整;
5,对静态接口类,抽象类等使用的地道。
6,设计模式,用的典型,经典。
7,代码执行效率高,算法优。
8,数据访问处理恰当,sql行文规范,缓存分配合理,内存占用合理。
备注2(希望大家不要误解):
1.胡适先生毕业典礼讲话:“一个人的业余时间用来做什么,就决定了他的将来”;
2.爱因斯坦说:“一个人活到六七十岁,大概有13年做工作,有17年是业余时间,此外是吃饭睡觉的时间。一个人能不能成才,关键在于利用你的17年,能够利用业余时间的人就能成才,否则就不能成才。”