当前位置: 首页>>代码示例>>C#>>正文


C# ISqlObject.ToString方法代码示例

本文整理汇总了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());
        }
开发者ID:ArsenShnurkov,项目名称:deveeldb,代码行数:22,代码来源:StringType.cs

示例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;
//.........这里部分代码省略.........
开发者ID:deveel,项目名称:deveeldb,代码行数:101,代码来源:StringType.cs


注:本文中的ISqlObject.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。