SQL 语句有很多函数如len(),now()等等。如何来生成这些函数。最近研究也写办法共大家参考。
一.首先建立一个建一个扩展类,控制只能允许这些函数出现,如果出现其他函数就直接报异常。
1 public static class SQLMethods 2 { 3 public static bool DB_In<T>(this T t, List<T> list) // in 4 { 5 return true; 6 } 7 public static Boolean DB_NotIn<T>(this T t, List<T> list) // not in 8 { 9 return true; 10 } 11 public static int DB_Length(this string t) // len(); 12 { 13 return 0; 14 } 15 public static bool DB_Like(this string t, string str) // like 16 { 17 return true; 18 } 19 public static bool DB_NotLike(this string t, string str) // not like 20 { 21 return true; 22 } 23 }