public void RunUnder(TheCode theCode) { try { Setup(); theCode(); } finally { Teardown(); } }
/// <summary> /// 替换字段标签 /// </summary> /// <param name="str"></param> /// <param name="c"></param> /// <param name="lastChar"></param> /// <param name="isline"></param> /// <returns></returns> private string ReplaceColumn(string str, TheCode.Model.Column c, string lastChar, bool isLine) { str = str.Replace(NameSpace, nameSpace); str = str.Replace(DatabaseName, databaseName); str = str.Replace(TableName, tableName); str = str.Replace(ColumnName_Template, c.ColumnName); //转型 if (regConvertTo.IsMatch(str)) { string temp = regConvertTo.Matches(str)[0].Value; if (c.IsNull == "1") //可为空的话 转换时需要加上数据库空字段(DBNull.Value)验证 { string s = temp.Replace("${ConvertTo[","").Replace("]}$",""); if (c.ColumnType == "Int16?" || c.ColumnType == "Int32?" || c.ColumnType == "Int64?" || c.ColumnType == "Uint16?" || c.ColumnType == "Uint32?" || c.ColumnType == "Uint64?" || c.ColumnType == "Boolean?" || c.ColumnType == "Byte?" || c.ColumnType == "SByte?" )//并且是值类型 { str = str.Replace(temp, s + " == DBNull.Value ? (" + c.ColumnType + ")null : " + String.Format(c.ConvertStr, s)); } else { str = str.Replace(temp, s + " == DBNull.Value ? null : " + String.Format(c.ConvertStr, s)); } } else { str = str.Replace(temp, String.Format(c.ConvertStr,temp.Replace("${ConvertTo[","").Replace("]}$",""))); } } str = str.Replace(IsPk_Template, c.IsPk == "1" ? "[主键] " : ""); str = str.Replace(IsIdentity_Template, c.IsIdentity == "1" ? "[自增长] " : ""); str = str.Replace(IsNull_Template, c.IsNull == "1" ? "[可为空] " : ""); str = str.Replace(DefaultValue_Template, c.DefaultValue != "" ? "[默认值:" + c.DefaultValue.Replace("(", "").Replace(")", "") + "] " : ""); str = str.Replace(ColumnType_Template, c.ColumnType); str = str.Replace(ColumnByte_Template, c.ColumnByte); str = str.Replace(ColumnLength_Template, c.ColumnLength); str = str.Replace(ColumnRemark_Template, c.ColumnRemark != "" ? "[备注:" + c.ColumnRemark + "] " : ""); return str; }