This commit is contained in:
610262374@qq.com
2017-03-06 20:04:28 +08:00
parent c24fc90871
commit 57fc975f38
3 changed files with 47 additions and 55 deletions

View File

@@ -177,31 +177,18 @@ namespace SqlSugar
return DateTime.TryParse(thisValue.ToString(), out outValue);
}
/// <summary>
/// 是邮箱?
/// </summary>
/// <param name="thisValue"></param>
/// <returns></returns>
public static bool IsEamil(this object thisValue)
{
if (thisValue == null) return false;
return Regex.IsMatch(thisValue.ToString(), @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$");
}
/// <summary>
/// 是手机?
/// </summary>
/// <param name="thisValue"></param>
/// <returns></returns>
public static bool IsMobile(this object thisValue)
{
if (thisValue == null) return false;
return Regex.IsMatch(thisValue.ToString(), @"^\d{11}$");
}
/// <summary>
/// 是座机?
/// </summary>
public static bool IsTelephone(this object thisValue)
{
if (thisValue == null) return false;
@@ -209,77 +196,47 @@ namespace SqlSugar
}
/// <summary>
/// 是身份证?
/// </summary>
/// <param name="thisValue"></param>
/// <returns></returns>
public static bool IsIDcard(this object thisValue)
{
if (thisValue == null) return false;
return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$");
}
/// <summary>
/// 是传真?
/// </summary>
/// <param name="thisValue"></param>
/// <returns></returns>
public static bool IsFax(this object thisValue)
{
if (thisValue == null) return false;
return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$");
}
/// <summary>
/// 是适合正则匹配?
/// </summary>
/// <param name="thisValue"></param>
/// <param name="pattern"></param>
/// <returns></returns>
public static bool IsMatch(this object thisValue, string pattern)
{
if (thisValue == null) return false;
Regex reg = new Regex(pattern);
return reg.IsMatch(thisValue.ToString());
}
/// <summary>
/// 是否是动态类型
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static bool IsAnonymousType(this Type type)
{
string typeName = type.Name;
return typeName.Contains("<>") && typeName.Contains("__") && typeName.Contains("AnonymousType");
}
/// <summary>
/// 是List类型
/// </summary>
/// <param name="thisValue"></param>
/// <returns></returns>
public static bool IsCollectionsList(this string thisValue)
{
return (thisValue + "").StartsWith("System.Collections.Generic.List");
}
/// <summary>
/// 是string[]类型
/// </summary>
/// <param name="thisValue"></param>
/// <returns></returns>
public static bool IsStringArray(this string thisValue)
{
return (thisValue + "").IsMatch(@"System\.[a-z,A-Z,0-9]+?\[\]");
}
/// <summary>
/// 是Enumerable
/// </summary>
/// <param name="thisValue"></param>
/// <returns></returns>
public static bool IsEnumerable(this string thisValue)
{
return (thisValue + "").StartsWith("System.Linq.Enumerable");
}
public static Type StringType = typeof (string);
public static bool IsClass(this Type thisValue)
{
return thisValue != StringType && thisValue.IsClass;
}
}
}

View File

@@ -22,6 +22,13 @@ namespace SqlSugar
public MappingColumnList MappingColumns { get; set; }
public MappingTableList MappingTables { get; set; }
public List<JoinQueryInfo> JoinQueryInfos { get; set; }
public bool IsJoin {
get
{
return JoinQueryInfos.IsValuable();
}
}
public ResolveExpressType ResolveType { get; set; }
public Expression Expression { get; set; }
public ExpressionResult Result
@@ -73,9 +80,13 @@ namespace SqlSugar
BaseResolve resolve = new BaseResolve(new ExpressionParameter() { Expression = this.Expression, Context = this });
resolve.Start();
}
public virtual string GetAsString(string fieldName, string fieldValue)
public virtual string GetAsString(string asName, string fieldValue)
{
return string.Format(" {0} {1} {2} ", fieldValue, "AS", fieldName);
return string.Format(" [{0}] {1} [{2}] ", fieldValue, "AS", asName);
}
public virtual string GetAsString(string asName, string fieldValue,string fieldShortName)
{
return string.Format(" [{0}].[{1}] {2} [{3}] ", fieldShortName, fieldValue, "AS", asName);
}
public virtual void Clear()
{

View File

@@ -85,10 +85,34 @@ namespace SqlSugar
base.Context.Result.CurrentParameter = null;
}
}
else if(item.GetType().IsClass&& item.GetType()!=ExpressionConst.StringType)
else if (item.Type.IsClass())
{
StringBuilder sb=new StringBuilder();
string prefix = Context.IsJoin ? memberName : "";
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
base.Context.Result.Append(sb.ToString());
foreach (var property in listProperties)
{
if (property.PropertyType.IsClass())
{
}
else
{
var columnName = property.Name;
if (Context.IsJoin)
{
// Context.GetAsString(prefix,item,)
}
else
{
Context.GetAsString(columnName, columnName);
}
}
}
}
else
{
}else{
Check.ThrowNotSupportedException(item.GetType().Name);
}
}