本文整理汇总了C#中ISqlObject.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ISqlObject.ToString方法的具体用法?C# ISqlObject.ToString怎么用?C# ISqlObject.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISqlObject
的用法示例。
在下文中一共展示了ISqlObject.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compare
public override int Compare(ISqlObject x, ISqlObject y)
{
if (x == null)
throw new ArgumentNullException("x");
if (!(x is ISqlString) ||
!(y is ISqlString))
throw new ArgumentException("Cannot compare objects that are not strings.");
if (x.IsNull && y.IsNull)
return 0;
if (x.IsNull && !y.IsNull)
return 1;
if (!x.IsNull && y.IsNull)
return -1;
// If lexicographical ordering,
if (Locale == null)
return LexicographicalOrder((ISqlString)x, (ISqlString)y);
return Collator.Compare(x.ToString(), y.ToString());
}
示例2: CastTo
/// <inheritdoc/>
public override ISqlObject CastTo(ISqlObject value, SqlType destType)
{
if (value is SqlLongString) {
var clob = (SqlLongString) value;
switch (destType.TypeCode) {
case SqlTypeCode.LongVarChar:
case SqlTypeCode.Clob: {
if (clob.IsNull)
return SqlLongString.Null;
var destStringType = (StringType) destType;
if (MaxSize > destStringType.MaxSize)
throw new InvalidCastException(String.Format("The destination type '{0}' is not large enough.", destStringType));
if (clob.Length > destStringType.MaxSize)
throw new InvalidCastException(String.Format("The source object is too large ({0} bytes) for the destination type '{1}'", clob.Length, destStringType));
return clob;
}
case SqlTypeCode.LongVarBinary:
case SqlTypeCode.Blob: {
if (clob.IsNull)
return SqlLongBinary.Null;
var destBinaryType = (BinaryType) destType;
if (clob.Length > destBinaryType.MaxSize)
throw new InvalidCastException(
String.Format("The source object is too large ({0} bytes) for the destination type '{1}'", clob.Length,
destBinaryType));
return new SqlLongBinary(clob.LargeObject);
}
default:
throw new InvalidCastException(String.Format("Cannot cast a CLOB of type '{0}' to '{1}'.", this, destType));
}
}
string str = value.ToString();
var sqlType = destType.TypeCode;
ISqlObject castedValue;
if (value.IsNull)
return SqlNull.Value;
switch (sqlType) {
case (SqlTypeCode.Bit):
case (SqlTypeCode.Boolean):
castedValue = ToBoolean(str);
break;
case (SqlTypeCode.TinyInt):
case (SqlTypeCode.SmallInt):
case (SqlTypeCode.Integer): {
var num = ToNumber(str);
if (num.IsNull) {
castedValue = num;
} else {
castedValue = new SqlNumber(num.ToInt32());
}
break;
}
case (SqlTypeCode.BigInt): {
var num = ToNumber(str);
if (num.IsNull) {
castedValue = num;
} else {
castedValue = new SqlNumber(num.ToInt64());
}
break;
}
case (SqlTypeCode.Float):
case (SqlTypeCode.Double): {
var num = ToNumber(str);
if (num.IsNull) {
castedValue = num;
} else {
castedValue = new SqlNumber(num.ToDouble());
}
break;
}
case (SqlTypeCode.Real):
case (SqlTypeCode.Numeric):
case (SqlTypeCode.Decimal):
castedValue = ToNumber(str);
break;
case (SqlTypeCode.Char):
castedValue = new SqlString(str.PadRight(((StringType)destType).MaxSize));
break;
case (SqlTypeCode.VarChar):
case (SqlTypeCode.String):
castedValue = new SqlString(str);
break;
case (SqlTypeCode.Date):
castedValue = ToDate(str);
break;
case (SqlTypeCode.Time):
castedValue = ToTime(str);
break;
//.........这里部分代码省略.........