📄 clsfield.cs
字号:
case "varbinary":
default:
sToReturn = m_iLength.ToString();
break;
}
return sToReturn;
}
/// <summary>
/// Purpose: returns the length value for this field. Most of the time this is a numeric value,
/// but sometimes this is the length of a membervariable.
/// </summary>
/// <param name="bStyleHungarian">Flag to use Hungarian Coding (true) or Microsoft caMel Style (false)</param>
/// <param name="bUseNullValueCheck">Flag to use the necessity of the Null value check. If true,
/// the length string for some fields is "[hungarianprefix][l/L]ength", which is a local variable generated
/// into the code, which holds the actual length at runtime. This is necessary to avoid nullvalueexceptions
/// when a NULL value is passed to [n]text fields and image fields, the length value of their SqlTypes object
/// is then not valid.</param>
/// <returns>The length to emit in the parameter declaration.</returns>
public string GetFieldLengthAsNETString(bool bStyleHungarian, bool bUseNullValueCheck)
{
string sToReturn;
bool bNullValueCheckNecessary = CheckIfNullValueCheckIsNeeded();
switch(m_sDataType)
{
case "image":
if(bUseNullValueCheck && bNullValueCheckNecessary)
{
sToReturn = PrefixMethodParameter("Length", "i", bStyleHungarian);
}
else
{
sToReturn = GetFieldAsNETParam(bStyleHungarian,true) + ".Length";
}
break;
case "text":
case "ntext":
if(bUseNullValueCheck && bNullValueCheckNecessary)
{
sToReturn = PrefixMethodParameter("Length", "i", bStyleHungarian);
}
else
{
sToReturn = GetFieldAsNETParam(bStyleHungarian,true) + ".Value.Length";
}
break;
case "int":
case "smallint":
case "tinyint":
case "bigint":
case "bit":
case "binary":
case "decimal":
case "sql_variant":
case "sysname":
case "datetime":
case "smalldatetime":
case "timestamp":
case "float":
case "real":
case "money":
case "smallmoney":
case "uniqueidentifier":
case "numeric":
case "varchar":
case "char":
case "nvarchar":
case "nchar":
case "varbinary":
default:
sToReturn = m_iLength.ToString();
break;
}
return sToReturn;
}
/// <summary>
/// Purpose: returns the type of the field as a .NET type, like 'SqlDecimal'.
/// </summary>
/// <returns>C# version of the field's type</returns>
public string GetFieldTypeAsNETType()
{
return m_slTypeToNETType[m_sDataType].ToString();
}
/// <summary>
/// Purpose: returns the type of the field as a C# cast type, like 'Decimal'.
/// </summary>
/// <returns>C# version of the field's cast type</returns>
public string GetFieldTypeAsCSCastType()
{
return m_slTypeToCSCastType[m_sDataType].ToString();
}
/// <summary>
/// Purpose: returns the type of the field as a VB cast type, like 'Decimal'.
/// Use this routine with CType(,)
/// </summary>
/// <returns>C# version of the field's cast type</returns>
public string GetFieldTypeAsVBCastType()
{
return m_slTypeToVBCastType[m_sDataType].ToString();
}
/// <summary>
/// Purpose: returns the type of the field as an SqlType type, like 'Decimal'.
/// </summary>
/// <returns>SqlType version of the field's type</returns>
public string GetFieldTypeAsSqlType()
{
return m_slTypeToSqlType[m_sDataType].ToString();
}
/// <summary>
/// Purpose: returns the fieldname usable as .NET Variable, inclusive 'm_' and prefix if necessary
/// </summary>
/// <param name="bStyleHungarian">Flag to use Hungarian Coding (true) or Microsoft caMel Style (false)</param>
/// <param name="bIsMember">Flag to prefix returned params with a 'm_' or '_', so it's a membervariable.</param>
/// <returns>String representation of field, usable as NET variable.</returns>
/// <remarks>It replaces spaces in fieldnames with a '_'. It's unwise to use spaces in databasefields, but
/// if you do, the tool will correctly handle these.</remarks>
public string GetFieldAsNETParam(bool bStyleHungarian, bool bIsMember)
{
string sFieldName=m_sFieldName.Replace(" ","_");
string sPrefix;
if(bIsMember)
{
if(bStyleHungarian)
{
sPrefix = "m_";
}
else
{
sPrefix = "_";
}
}
else
{
sPrefix="";
}
if(bStyleHungarian)
{
return sPrefix + m_slTypeToPrefix[m_sDataType].ToString() +
sFieldName.Substring(0,1).ToUpper() + sFieldName.Substring(1, sFieldName.Length-1);
}
else
{
return sPrefix + sFieldName.Substring(0,1).ToLower() + sFieldName.Substring(1, sFieldName.Length-1);
}
}
/// <summary>
/// Purpose: returns the fieldname usable as .NET Property, inclusive prefix if necessary
/// </summary>
/// <param name="bPrefixProperties">Flag to prefix properties using Hungarian Coding (true) or just
/// use Microsoft caMel Style names (false)</param>
/// <returns>String representation of field, usable as .NET Property.</returns>
/// <remarks>It replaces spaces in fieldnames with a '_'. It's unwise to use spaces in databasefields, but
/// if you do, the tool will correctly handle these.</remarks>
public string GetFieldAsNETProperty(bool bPrefixProperties)
{
string sFieldName=m_sFieldName.Replace(" ","_");
if(bPrefixProperties)
{
return m_slTypeToPrefix[m_sDataType].ToString() +
sFieldName.Substring(0,1).ToUpper() + sFieldName.Substring(1, sFieldName.Length-1);
}
else
{
return sFieldName.Substring(0,1).ToUpper() + sFieldName.Substring(1, sFieldName.Length-1);
}
}
/// <summary>
/// Purpose: prefixes the given method parameter according to the settings set.
/// </summary>
/// <param name="sParameterName">Name of the method parameter to prefix</param>
/// <param name="sTypePrefix">Type prefix to add as a prefix if method parameters should be prefixed</param>
/// <param name="bStyleHungarian">Flag if hungarian coding should be used (true) or not (false)</param>
/// <returns>Name of method parameter according to the settings set</returns>
private string PrefixMethodParameter(string sParameterName, string sTypePrefix, bool bStyleHungarian)
{
if(bStyleHungarian)
{
return sTypePrefix + sParameterName;
}
else
{
return sParameterName.Substring(0,1).ToLower() + sParameterName.Substring(1,sParameterName.Length-1);
}
}
#region Class Property Declarations
public string sFieldName
{
get { return m_sFieldName; }
}
public bool bIsExcluded
{
get { return m_bIsExcluded; }
set { m_bIsExcluded = value; }
}
public SortedList slTypeToPrefix
{
set { m_slTypeToPrefix=value; }
}
public SortedList slTypeToNETType
{
set { m_slTypeToNETType=value; }
}
public SortedList slTypeToCSCastType
{
set { m_slTypeToCSCastType=value; }
}
public SortedList slTypeToVBCastType
{
set { m_slTypeToVBCastType=value; }
}
public SortedList slTypeToSqlType
{
set { m_slTypeToSqlType=value; }
}
public string sDataType
{
get { return m_sDataType; }
set { m_sDataType = value; }
}
public int iOrdinalPosition
{
get { return m_iOrdinalPosition; }
set { m_iOrdinalPosition = value; }
}
public int iLength
{
get { return m_iLength; }
set { m_iLength = value; }
}
public int iPrecision
{
get
{
//////////////
// .NET v1.0 BUG WORKAROUND: Precision can't be > 38. SQLServer 's float has
// a precision 53. We have to cap the precision to 38, until MS fixes this
// bug
/////////////
if(m_iPrecision>38)
{
return 38;
}
else
{
return m_iPrecision;
}
}
set { m_iPrecision = value; }
}
public int iScale
{
get { return m_iScale; }
set { m_iScale = value; }
}
public bool bIsComputed
{
get { return m_bIsComputed; }
set { m_bIsComputed = value; }
}
public bool bIsIdentity
{
get { return m_bIsIdentity; }
set { m_bIsIdentity = value; }
}
public bool bIsRowGUIDColumn
{
get { return m_bIsRowGUIDColumn; }
set { m_bIsRowGUIDColumn = value; }
}
public bool bIsForeignKey
{
get { return m_bIsForeignKey; }
set { m_bIsForeignKey = value; }
}
public bool bIsPrimaryKey
{
get { return m_bIsPrimaryKey; }
set { m_bIsPrimaryKey = value; }
}
public bool bIsNullable
{
get { return m_bIsNullable; }
set { m_bIsNullable = value; }
}
public bool bHasUniqueConstraint
{
get { return m_bHasUniqueConstraint; }
set { m_bHasUniqueConstraint = value; }
}
public bool bIsTimeStamp
{
get { return (m_sDataType.ToLower() == "timestamp"); }
}
public string sDefaultValue
{
get { return m_sDefaultValue; }
set { m_sDefaultValue = value; }
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -